diff options
author | 2022-08-25 00:12:20 +0800 | |
---|---|---|
committer | 2022-08-24 09:12:20 -0700 | |
commit | e6a1209c53adb3056263b894d774b30ee70a3188 (patch) | |
tree | 96a90345be58a044781373a938f13fe133bb71e0 | |
parent | f2316a8eda7765c8be2d1df8d2d6171e287ff1a1 (diff) | |
download | bun-e6a1209c53adb3056263b894d774b30ee70a3188.tar.gz bun-e6a1209c53adb3056263b894d774b30ee70a3188.tar.zst bun-e6a1209c53adb3056263b894d774b30ee70a3188.zip |
Fix clearTimeout and linux timeout (#1138)
-rw-r--r-- | src/bun.js/api/bun.zig | 14 | ||||
-rw-r--r-- | src/io/io_linux.zig | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 105add52c..7c2dd58aa 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -2188,8 +2188,6 @@ pub const Timer = struct { this.io_task.?.deinit(); var task = Timeout.TimeoutTask.createOnJSThread(VirtualMachine.vm.allocator, global, this) catch unreachable; VirtualMachine.vm.timer.timeouts.put(VirtualMachine.vm.allocator, this.id, this) catch unreachable; - VirtualMachine.vm.timer.active +|= 1; - VirtualMachine.vm.active_tasks +|= 1; this.io_task = task; task.schedule(); } @@ -2198,6 +2196,13 @@ pub const Timer = struct { if (this.repeat) return; + + VirtualMachine.vm.timer.active -|= 1; + VirtualMachine.vm.active_tasks -|= 1; + } else { + // the active tasks count is already cleared for canceled timeout, + // add one here to neutralize the `-|= 1` in event loop. + VirtualMachine.vm.active_tasks +|= 1; } this.clear(global); @@ -2214,8 +2219,6 @@ pub const Timer = struct { task.deinit(); } VirtualMachine.vm.allocator.destroy(this); - VirtualMachine.vm.timer.active -|= 1; - VirtualMachine.vm.active_tasks -|= 1; } }; @@ -2270,6 +2273,9 @@ pub const Timer = struct { if (comptime is_bindgen) unreachable; var timer: *Timeout = VirtualMachine.vm.timer.timeouts.get(id.toInt32()) orelse return; timer.cancelled = true; + VirtualMachine.vm.timer.active -|= 1; + // here we also remove the active task count added in event_loop. + VirtualMachine.vm.active_tasks -|= 2; } pub fn clearTimeout( diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig index d7a164665..dfad7e795 100644 --- a/src/io/io_linux.zig +++ b/src/io/io_linux.zig @@ -769,7 +769,7 @@ pub const Completion = struct { }, .timeout => { var op = &completion.operation.timeout; - linux.io_uring_prep_timeout(sqe, &op.timespec, 1, 0); + linux.io_uring_prep_timeout(sqe, &op.timespec, 0, 0); }, .write => |op| { linux.io_uring_prep_write( |