ITADN

Possible stack overflow with a large amount of queued events

#4542OpenJo-Meer 创建于 2026-03-24
B - bugDS - web
J
Jo-Meercommented
### Description Hi, I am developing a Slint application which uses winit. One of the targets is wasm. The application gets regulary messages over a websocket connection. These messages are then handled by the winit event loop (not directly but over slint). # Observed issue The issue appears when the tab is in the background and chrome/edge sets its `Lifecycle State` to sleeping. This state can be forced at `chrome://discards`. This throttles all timers and also the processing of the websocket messages. When I switch back to the app after a few minutes it is completly frozen. # Investigation First I am not familiar with the winit code, so I am not sure about my conclusion. I noticed that when switching back to the tab, there are roughly ~ 15000 queued events here https://github.com/rust-windowing/winit/blob/5a74bf0aabfe8e0605313b2692a111fb342dfc81/winit-web/src/event_loop/runner.rs#L51. We send lots of messages over the websocket connection. And the browser seems to cache them when the tab is sleeping. They are then applied at once. If I understand the code correctly the `handle_event` method https://github.com/rust-windowing/winit/blob/5a74bf0aabfe8e0605313b2692a111fb342dfc81/winit-web/src/event_loop/runner.rs#L653 then proceeds to handle all queued events. With (many) logs I noticed that the processing stops suddenly in the middle of all events and and all following `send_events` calls https://github.com/rust-windowing/winit/blob/5a74bf0aabfe8e0605313b2692a111fb342dfc81/winit-web/src/event_loop/runner.rs#L551 result in the error case here: https://github.com/rust-windowing/winit/blob/5a74bf0aabfe8e0605313b2692a111fb342dfc81/winit-web/src/event_loop/runner.rs#L568 The runner seems to be borrowed forever. # Possible fix I noticed `handle_event` is called recursively. Which may can be a problem with over 15000 queued events. I transformed it into a loop which seems to fix the problem. I think there is a silent(?) stack overflow, leaving the runner in a borrowed state. Maybe initiated from a requestAnimationFrame. But I am not sure about that. ### Tested browsers Chrome, Microsoft Edge ### Tested devices Windows (Chrome/Edge) ### Winit version 0.30.13
2 条评论