Skip to content

Commit 7625606

Browse files
committed
[Edge] Cancel the timer from running when we are done with it
Each use of a timer creates a User Object in Windows, and once we have stopped waiting for our desired event we don't need the cancellation tracking anymore. If there are lots of calls to processOSMessagesUntil, such as repeated browser.setText within the MAXIMUM_OPERATION_TIME (5 second) window, we can end up with a huge growth in the number of User Objects, leading to potential `SWTError: No more handles` errors elsewhere in the client code. Fixes #2806
1 parent 28bb9b4 commit 7625606

File tree

1 file changed

+3
-1
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

1 file changed

+3
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,16 @@ private static void processOSMessagesUntil(Supplier<Boolean> condition, Consumer
551551
MSG msg = new MSG();
552552
AtomicBoolean timeoutOccurred = new AtomicBoolean();
553553
// The timer call also wakes up the display to avoid being stuck in display.sleep()
554-
display.timerExec((int) MAXIMUM_OPERATION_TIME.toMillis(), () -> timeoutOccurred.set(true));
554+
Runnable runnable = () -> timeoutOccurred.set(true);
555+
display.timerExec((int) MAXIMUM_OPERATION_TIME.toMillis(), runnable);
555556
while (!display.isDisposed() && !condition.get() && !timeoutOccurred.get()) {
556557
if (OS.PeekMessage(msg, 0, 0, 0, OS.PM_NOREMOVE | OS.PM_QS_POSTMESSAGE)) {
557558
display.readAndDispatch();
558559
} else {
559560
display.sleep();
560561
}
561562
}
563+
display.timerExec(-1, runnable);
562564
if (!condition.get()) {
563565
timeoutHandler.accept(createTimeOutException());
564566
}

0 commit comments

Comments
 (0)