diff options
author | 2022-12-01 20:46:16 -0800 | |
---|---|---|
committer | 2022-12-01 20:46:54 -0800 | |
commit | f408749182f49607902921c55307f2cf94eb23db (patch) | |
tree | ac279aa9eeab70edd8d1fe43ee5212e7758e8f84 /src | |
parent | 92da72beb03dd686209428fcd0951b57d41e854c (diff) | |
download | bun-f408749182f49607902921c55307f2cf94eb23db.tar.gz bun-f408749182f49607902921c55307f2cf94eb23db.tar.zst bun-f408749182f49607902921c55307f2cf94eb23db.zip |
Fix timers keeping process alive unnecessarily
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/event_loop.zig | 9 | ||||
-rw-r--r-- | src/deps/uws.zig | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 53b6dcf1f..30cae84dd 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -308,10 +308,7 @@ pub const EventLoop = struct { global_vm.drainMicrotasks(); } - if (this.tasks.count == 0) { - this.tasks.head = 0; - } - + this.tasks.head = if (this.tasks.count == 0) 0 else this.tasks.head; return @truncate(u32, counter); } @@ -484,8 +481,8 @@ pub const EventLoop = struct { if (this.virtual_machine.uws_event_loop == null) { var actual = uws.Loop.get().?; this.virtual_machine.uws_event_loop = actual; - this.gc_timer = uws.Timer.create(actual, this); - this.gc_repeating_timer = uws.Timer.create(actual, this); + this.gc_timer = uws.Timer.createFallthrough(actual, this); + this.gc_repeating_timer = uws.Timer.createFallthrough(actual, this); var gc_timer_interval: i32 = 1000; if (this.virtual_machine.bundler.env.map.get("BUN_GC_TIMER_INTERVAL")) |timer| { diff --git a/src/deps/uws.zig b/src/deps/uws.zig index 20640948a..6db662c00 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -351,6 +351,15 @@ pub const Timer = opaque { return us_create_timer(loop, 0, @sizeOf(Type)); } + pub fn createFallthrough(loop: *Loop, ptr: anytype) *Timer { + const Type = @TypeOf(ptr); + + // never fallthrough poll + // the problem is uSockets hardcodes it on the other end + // so we can never free non-fallthrough polls + return us_create_timer(loop, 1, @sizeOf(Type)); + } + pub fn set(this: *Timer, ptr: anytype, cb: ?fn (*Timer) callconv(.C) void, ms: i32, repeat_ms: i32) void { us_timer_set(this, cb, ms, repeat_ms); var value_ptr = us_timer_ext(this); |