f35530b523
Microsoft Remote Desktop for Mac was observed to garble Chinese text typed through its local Pinyin IME: the composed characters would land with pieces missing or extra characters deleted from the document. Root cause, confirmed with debug logging plus dbus-monitor on the live ibus session bus: the client forwards the raw pre-composition keystrokes over the normal RDP keyboard channel while composing (these reach XrdpIme's process-key-event handler and, since it never consumes anything, get typed into the document as literal ASCII), then once composition finishes sends a compensating burst of Backspace keystrokes sized to exactly undo them, interleaved with the final composed text arriving over the separate TS_UNICODE_KEYBOARD_EVENT side channel. The two channels have no ordering guarantee, so the side-channel commit could land in the middle of the client's own backspace cleanup and get partially deleted. Measured the backspace burst against the leaked raw-character count across several phrases (23-for-23, 29-for-29) - it's always exactly right, so this is a pure interleaving race, not a client miscount. That makes it fixable server-side: xrdp_input_queue_source_prepare/ _check now withhold a queued commit until raw key traffic on the engine has been quiet for XRDP_INPUT_COMMIT_QUIET_US (100ms), so the client's own cleanup has time to finish first, capped by XRDP_INPUT_COMMIT_MAX_WAIT_US (500ms) so back-to-back composition can't delay a commit indefinitely. This is an empirical mitigation tuned to observed client behaviour, not a protocol guarantee. Also fixes two latent data races found while reviewing this code against the cross-thread invariants already documented at the top of the file: g_engine and last_input_name are written by the IBus thread (engine enable/disable, an unexpected daemon disconnect) but were read and, for last_input_name, also written directly by xrdp_input_enable() on chansrv's own thread with no synchronization - unlike `bus`, which already gets this treatment. Both now follow the same publish/clear-under-state_mutex pattern as `bus`. Added IBUS-KEY/IBUS-COMMIT debug logging used to diagnose this. Verified live against a real Microsoft Remote Desktop for Mac client connected to an xrdp/ibus session: multiple Chinese phrases of varying length composed and committed cleanly with the debounce in place, after reliably reproducing the interleaved garbling without it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>