Skip to content

fix(tauri-runtime-wry): handle event loop queue overflow with backpressure and coalescing - #15897

Open
Br1skyy wants to merge 1 commit into
tauri-apps:devfrom
Br1skyy:fix/event-emit-crash
Open

fix(tauri-runtime-wry): handle event loop queue overflow with backpressure and coalescing#15897
Br1skyy wants to merge 1 commit into
tauri-apps:devfrom
Br1skyy:fix/event-emit-crash

Conversation

@Br1skyy

@Br1skyy Br1skyy commented Aug 20, 2026

Copy link
Copy Markdown

Fixes #8177

Problem

Windows PostMessageW has a per-thread message queue limit. When window.emit() is called from many worker threads at high rate, the queue can overflow and PostMessageW fail with error 1816 (ERROR_NOT_ENOUGH_QUOTA). Right now these messages get silently dropped.

I test by calling PostMessageW directly 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 PostMessageW only 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 into PostMessageW directly. On Windows 10 or under heavy system load the queue can still overflow.

What this PR do

  1. Backpressure queue (PendingQueue): When send_event fail, fire-and-forget messages get queued and retried next MainEventsCleared. Getter messages with Sender not queued (would deadlock). Queue capped at 10000, oldest removed when full.

  2. EvaluateScript coalescing: Multiple EvaluateScript for same webview get merged, only latest kept. Less queue pressure from fast emit calls.

  3. Logging: All silent let _ = proxy.send_event(...) replaced with log::warn! so user can see when messages fail.

Test

  • 8 unit test for PendingQueue (all pass): push/drain, capacity limit, coalescing, order preservation
  • Repro app with 32 threads x 1M events, no crash, no regression
  • Raw PostMessageW flood test from 4/8/16 threads confirm the OS quota limit exist (89-97% message loss)
  • On v2 + Windows 11, 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 PostMessageW quota is exceeded.

…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.
@Br1skyy
Br1skyy requested a review from a team as a code owner August 20, 2026 00:33
@Legend-Master

Copy link
Copy Markdown
Contributor

Thanks for contributing, but please provide a repro as mentioned in #8177 (comment)

@Legend-Master Legend-Master added status: needs repro This issue needs to a minimal complete and reproducible example status: waiting Waiting on author labels Aug 20, 2026
@Br1skyy

Br1skyy commented Aug 20, 2026

Copy link
Copy Markdown
Author

Thanks for contributing, but please provide a repro as mentioned in #8177 (comment)

Sorry, working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs repro This issue needs to a minimal complete and reproducible example status: waiting Waiting on author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Event emit crashes app with high call rate

2 participants