{"record":{"id":"834b57bdfc304a26","repo":"linebender/druid","slug":"keyboard-event-processing-failed","errorCode":null,"errorMessage":"keyboard event processing failed","messagePattern":"keyboard event processing failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"druid-shell/src/backend/wayland/keyboard.rs","lineNumber":279,"sourceCode":"\n            // generate repeat keypresses.\n            handle\n                .insert_source(repeat, |event, timer, state| {\n                    timer.add_timeout(state.1.repeat.rate, event.clone());\n                    state.1.keystroke(&event);\n                })\n                .unwrap();\n\n            tracing::debug!(\"keyboard event loop initiated\");\n            eventloop\n                .run(\n                    std::time::Duration::from_secs(60),\n                    &mut (signal, Keyboard::default()),\n                    |_ignored| {\n                        tracing::trace!(\"keyboard event loop idle\");\n                    },\n                )\n                .expect(\"keyboard event processing failed\");\n            tracing::debug!(\"keyboard event loop completed\");\n        });\n\n        state\n    }\n}\n\nstruct ModMap(u32, Modifiers);\n\nimpl ModMap {\n    fn merge(self, m: Modifiers, mods: u32, locked: u32) -> Modifiers {\n        if self.0 & mods == 0 && self.0 & locked == 0 {\n            return m;\n        }\n\n        m | self.1\n    }\n}","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/backend/wayland/keyboard.rs#L261-L297","documentation":"After initializing the keyboard event loop, the Wayland backend runs `eventloop.dispatch(Duration::from_secs(60), ...)` in a loop-ish dispatch call; a dispatch returning Err (internal calloop error, dispatcher callback failure, or io error on the event source) is unwrapped with expect('keyboard event processing failed'), panicking the keyboard thread and ending key input/repeat handling.","triggerScenarios":"calloop dispatch returning Err during keyboard event processing: the inserted rx source or the key-repeat timer fails, the wayland connection's rx channel errors, or the dispatcher state (LoopSignal, Keyboard) is corrupted; also raised if dispatch is called on an already-signaled/dead loop.","commonSituations":"Wayland compositor restarts or connection drops mid-session; key-repeat timer misbehaving after rapid key events; panics inside the dispatched callback propagating out as dispatch errors; long-running sessions hitting resource exhaustion.","solutions":["Update druid-shell and calloop — dispatch error handling in the wayland keyboard backend has been improved in newer versions.","Check for panics/errors inside the keyboard dispatch callback; fix the underlying source error.","Verify the wayland connection remains alive; reconnect handling (compositor restart) may be required.","In a patched build, replace expect with a logged error so keyboard failure degrades gracefully instead of killing the thread.","Reproduce with WAYLAND_DEBUG=1 to identify which event/source fails and report upstream."],"exampleFix":"// before\neventloop.dispatch(std::time::Duration::from_secs(60), &mut (signal, Keyboard::default()), |_ignored| {})\n    .expect(\"keyboard event processing failed\");\n\n// after\nif let Err(e) = eventloop.dispatch(std::time::Duration::from_secs(60), &mut (signal, Keyboard::default()), |_ignored| {}) {\n    tracing::error!(\"keyboard event dispatch failed: {e}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// wrap dispatch instead of expect:\nmatch eventloop.dispatch(timeout, &mut state, |_ignored| {}) {\n    Ok(()) => {}\n    Err(e) => log::error!(\"keyboard dispatch failed: {e}\"), // log and continue/reconnect\n}","preventionTips":["Avoid panicking inside keyboard dispatch callbacks; route errors to logging.","Handle compositor restarts / wayland connection loss explicitly.","Keep calloop and druid-shell versions current and compatible.","Reproduce odd input failures with WAYLAND_DEBUG=1 before they crash the loop."],"tags":["wayland","linux","calloop","keyboard","panic","event-loop"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}