RFR: 8351733: [macos] Crash when creating too many nested event loops [v3]
Martin Fox
mfox at openjdk.org
Tue Mar 25 20:50:19 UTC 2025
On Mon, 24 Mar 2025 18:30:56 GMT, Martin Fox <mfox at openjdk.org> wrote:
>> There is an undocumented limit on nesting calls to CFRunLoopRun (or the equivalent wrapper NSRunLoop methods). When the limit is hit the OS terminates the Java app. The situation arises when a JavaFX app creates too many nested event loops from within Platform.runLater runnables.
>>
>> This PR doesn't change the limit (which is 250+ nested loops) but it does throw an exception just before the limit is reached so a JavaFX developer will get a useful Java stack trace instead of an OS crash log.
>>
>> On the Mac the nested event loop has two stages: first we ask the run loop to run, then we pull an event out and process it. A Platform.runLater runnable is executed in the first stage so if the runnable starts a new nested event loop the system will re-enter CFRunLoopRun. The same isn't true if an input event handler starts a new nested event loop; at that point we're in stage two and are past the call to CFRunLoopRun.
>
> Martin Fox has updated the pull request incrementally with one additional commit since the last revision:
>
> Lower limit on run loop nesting
For customers creating cross-platform apps having the limit be the same on all platforms would simplify testing. If this was per-platform we would need to publish the limits since developers would want to test on the most restrictive platform. And my guess is that we would set Mac and Windows to be close to the same (around 240) and Linux would be the outlier. So I'm leaning toward a cross-platform limit.
With that said documenting a cross-platform limit is awkward. Why is there a limit and why is it 240? There's one reason on the Mac, a different one on Windows, and Linux is just following the lead of the other two. In the cross-platform version of this PR I included a public constant but didn't even try to explain where the number came from. I'm tempted to make this non-public but have it show up in the exception description.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1741#issuecomment-2752509820
More information about the openjfx-dev
mailing list