Skip to content

[Win32] Make Edge only process relevant OS messages #1789 #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

HeikoKlare
Copy link
Contributor

When waiting for initialization of the WebView2 component in the Edge implementation, OS messages are processed by peeking the queue and performing a display.readAndDispatch() in case a message is present. The call to OS.PeekMessage() does, however, already perform some processing of the messages. In fact, Edge is not supposed to process all kinds of OS messages at all (like paint or input events) but should rather only process the WebView2 initialization callback message, arriving as a posted OS message. This change thus limits the message peeking inside Edge to only process the message type PM_QS_POSTMESSAGE.

Fixes #1789

Copy link
Contributor

github-actions bot commented Feb 3, 2025

Test Results

   502 files  ±0     502 suites  ±0   10m 11s ⏱️ +59s
 4 334 tests ±0   4 320 ✅ ±0   14 💤 ±0  0 ❌ ±0 
16 575 runs  ±0  16 466 ✅ ±0  109 💤 ±0  0 ❌ ±0 

Results for commit c8eee7d. ± Comparison against base commit 920fe85.

♻️ This comment has been updated with latest results.

@HeikoKlare HeikoKlare marked this pull request as ready for review February 3, 2025 20:35
@fedejeanne
Copy link
Contributor

@amartya4256 here's the reproducer so you can test locally: vi-eclipse/Eclipse-Platform#223 (comment)

@@ -510,7 +510,7 @@ private static void processOSMessagesUntil(Supplier<Boolean> condition, Consumer
// The timer call also wakes up the display to avoid being stuck in display.sleep()
display.timerExec((int) MAXIMUM_OPERATION_TIME.toMillis(), () -> timeoutOccurred.set(true));
while (!display.isDisposed() && !condition.get() && !timeoutOccurred.get()) {
if (OS.PeekMessage(msg, 0, 0, 0, OS.PM_NOREMOVE)) {
if (OS.PeekMessage(msg, 0, 0, 0, OS.PM_NOREMOVE | OS.PM_QS_POSTMESSAGE)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we can make it more specific to the edge instance by providing a hwnd? But another concern is, does the filtering mean that the possibility of this falling into display.sleep() is higher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be possible, but we need to be aware that this will not mean that this message is processed by display.readAndDispatch() then, as there messages are processed by priority. Posted messages have high priority and will be processed before, e.g., input events, so if there is a posted message, it will always be processed before an eventual input event also being in the queue.
This change is only avoiding that we run into display.readAndDispatch() without a message being in the queue as that has already been processed via this PeekMessage call.

The possibility of falling into display.sleep() is of course higher, but that's also by intent. We limit processing to specific messages, so instead of processing other messages we will sleep and wait for the next message instead. But since we will wake from display.sleep() whenever a new message arrives, this is not an issue. Or do you have any further concerns here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it keeps waking up with new messages, it should be fine. The only concern was about, in an imaginary scenario, no messages are received for a long time, it means the display thread will be sleeping for that period - which will freeze the UI, right? But of course we need to test it out practically. For me locally it worked just fine so I would be in the favour of merging this and waiting for the feedback from the users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we don't receive messages (which also means that Edge initialization fails), we run into our timeout. That's what we have the display.timerExec() for, setting the timeout value and breaking the loop execution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then its safe from the infiite sleeping problem here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way I always wondered why there is no Display.sleep(timeout) is it not supported on the OS level? How does a "real" native app handle this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. If you are simply spinning the queue, waiting for messages and processing them, such a timeout should actually not be necessary, as without any messages arriving from the SO there is something completely broken anyway. In the case we have here, if we simply spinned the whole event loop instead of limiting to processing specific messages, we would not run into that situation either (see #1773).

Copy link
Contributor

@akoch-yatta akoch-yatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without having proper knowledge of the messages queues in windows, limiting peeking into the message queue as much as possible, makes sense to me.

…1789

When waiting for initialization of the WebView2 component in the Edge
implementation, OS messages are processed by peeking the queue and
performing a display.readAndDispatch() in case a message is present. The
call to OS.PeekMessage() does, however, already perform some processing
of the messages. In fact, Edge is not supposed to process all kinds of
OS messages at all (like paint or input events) but should rather only
process the WebView2 initialization callback message, arriving as a
posted OS message. This change thus limits the message peeking inside
Edge to only process the message type PM_QS_POSTMESSAGE.

Fixes eclipse-platform#1789
@HeikoKlare HeikoKlare merged commit 54dad6c into eclipse-platform:master Feb 5, 2025
14 checks passed
@HeikoKlare HeikoKlare deleted the issue-1789 branch February 5, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edge: unexpected concurrent processing of OS messages Edge: unexpected concurrent processing of OS messages
5 participants