RFR: 8221261: deadlock of CInputMethod.characterIndexForPoint and webkit.InputMethodClientImpl.getLocationOffset
Kevin Rushforth
kcr at openjdk.org
Fri Dec 22 20:56:37 UTC 2023
On Fri, 22 Dec 2023 11:27:00 GMT, Johannes Bechberger <jbechberger at openjdk.org> wrote:
> A dead-lock is caused by the interaction of MacOS, the AWTEventQueue and JavaFX when the users pressed the Caps Lock key while the AWTEventQueue is processing another event (more on this in the issue). The bug depends on the specific timing of the event sending and can apparently be prevented by finishing all incoming OS events directly while the LWCToolkit.invokeAndWait method is executed.
>
> This fix is tested and fixes the issue.
>
> I attached a small
> [reproducer](https://github.com/openjdk/jdk/files/13751865/Archive.zip), just run it with `mvn install package javafx:run`.
I can confirm that the proposed fix in this PR does eliminate the deadlocks, although as per the comment from Anton I referred to above, it is likely to have some side effects.
I did a quick prototype of Anton's idea, and ended up changing all five of the `invokeAndWait` calls in `CInputMethod` to pass in the `processEvents` flag, since just changing the two he pointed out did not fix all the possible sources of deadlock. Doing that, while leaving all other calls to `invokeAndWait` alone, is sufficient to avoid the deadlock. This might end up being the best fix, since it is less intrusive (thus less risky) that changing all invokeAntWait calls, and as Arunprasad noted in the JBS bug, we don't know of a way to avoid the deadlock by just changing FX code.
While doing some testing of the fix I ran into a few crashes where native WebKit code is being called on the AWT Event thread, which suggest that other JavaFX WebView InputMethodClientImpl methods will likely need the same treatment that `firstRectForCharacterRange` and `characterIndexForPoint` got in the fix for [JDK-8196011](https://bugs.openjdk.org/browse/JDK-8196011). This crash isn't caused by fixing the deadlock, since I see it intermittently with a JDK without the deadlock fix (e.g., JDK 21.0.1). I'll file a separate JavaFX bug to track the crash.
We can pick this up in the new year, since no one on our end will be around to look at it before then.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17184#issuecomment-1868062432
More information about the client-libs-dev
mailing list