core: rate limit BEL character processing

If the BEL character is received too frequently, the GUI thread can be
starved and Ghostty will lock up and eventually crash. This PR limits
BEL handling to 1 per 100ms.

Fixes #9800.
pull/9810/head
Jeffrey C. Ollie 2025-12-04 12:30:51 -06:00
parent 6502922bb6
commit 68426dc21a
No known key found for this signature in database
GPG Key ID: 1BB9EB7EA602265B
1 changed files with 9 additions and 1 deletions

View File

@ -155,6 +155,9 @@ command_timer: ?std.time.Instant = null,
/// Search state
search: ?Search = null,
/// Used to rate limit BEL handling.
last_bell_time: ?std.time.Instant = null,
/// The effect of an input event. This can be used by callers to take
/// the appropriate action after an input event. For example, key
/// input can be forwarded to the OS for further processing if it
@ -1026,7 +1029,12 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
.password_input => |v| try self.passwordInput(v),
.ring_bell => {
.ring_bell => bell: {
const now = std.time.Instant.now() catch unreachable;
if (self.last_bell_time) |last| {
if (now.since(last) < 100 * std.time.ns_per_ms) break :bell;
}
self.last_bell_time = now;
_ = self.rt_app.performAction(
.{ .surface = self },
.ring_bell,