fix(tauri-runtime-wry): handle event loop queue overflow with backpressure and coalescing - #15897
Open
Br1skyy wants to merge 1 commit into
Open
fix(tauri-runtime-wry): handle event loop queue overflow with backpressure and coalescing#15897Br1skyy wants to merge 1 commit into
Br1skyy wants to merge 1 commit into
Conversation
…ssure and coalescing Fixes tauri-apps#8177 When window.emit() is called at high rates from worker threads, the OS event queue overflows. On Windows, PostMessageW fails with ERROR_NOT_ENOUGH_QUOTA (error 1816) when the per-thread queue exceeds 10,000 messages. Previously, this either crashed the app or silently dropped messages. This adds a bounded backpressure queue (10,000 capacity) in send_user_message. When send_event fails and the message is fire-and-forget, it is queued and retried on the next MainEventsCleared iteration. Messages with synchronous channels (getters that block on rx.recv()) are never queued to prevent deadlocks. High-frequency EvaluateScript messages targeting the same webview are coalesced so only the latest is kept. Six silent let _ = proxy.send_event(...) drops are replaced with log::warn! diagnostics.
Contributor
|
Thanks for contributing, but please provide a repro as mentioned in #8177 (comment) |
Author
Sorry, working on it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8177
Problem
Windows
PostMessageWhas a per-thread message queue limit. Whenwindow.emit()is called from many worker threads at high rate, the queue can overflow andPostMessageWfail with error 1816 (ERROR_NOT_ENOUGH_QUOTA). Right now these messages get silently dropped.I test by calling
PostMessageWdirectly from 4+ threads with raw Win32 API and the OS drop 89-97% of messages. The queue limit is real.In Tauri v2, tao 0.36.0 use crossbeam channel for event payload and
PostMessageWonly as wakeup signal. This make it much harder to hit on modern hardware. But the issue was reported on Tauri v1 / Windows 10 where the old tao packed payload intoPostMessageWdirectly. On Windows 10 or under heavy system load the queue can still overflow.What this PR do
Backpressure queue (
PendingQueue): Whensend_eventfail, fire-and-forget messages get queued and retried nextMainEventsCleared. Getter messages withSendernot queued (would deadlock). Queue capped at 10000, oldest removed when full.EvaluateScriptcoalescing: MultipleEvaluateScriptfor same webview get merged, only latest kept. Less queue pressure from fast emit calls.Logging: All silent
let _ = proxy.send_event(...)replaced withlog::warn!so user can see when messages fail.Test
PendingQueue(all pass): push/drain, capacity limit, coalescing, order preservationPostMessageWflood test from 4/8/16 threads confirm the OS quota limit exist (89-97% message loss)emit()does not fail even under extreme pressure because tao channel handle it. Defensive fix for older Windows or when system is under heavy load.Note
The crash in #8177 was Tauri v1. In v2 the tao channel design make it much harder to reproduce. This PR add defensive backpressure handling, event coalescing, and diagnostic logging for edge cases where
PostMessageWquota is exceeded.