From 157a22c0eb7704bb72245b01bb3d564b522d7f3d Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 26 Jan 2024 00:47:51 -0800 Subject: [PATCH] Fix some things --- src/bun.js/event_loop.zig | 22 ++++++++++++++++++++-- src/install/install.zig | 8 ++++---- src/install/lifecycle_script_runner.zig | 20 ++++++++++---------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 3ffedd7cc0..bdbdf49692 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -1625,6 +1625,24 @@ pub const MiniEventLoop = struct { } } + pub fn tickWithoutIdle( + this: *MiniEventLoop, + context: *anyopaque, + ) void { + defer this.onAfterEventLoop(); + + while (true) { + _ = this.tickConcurrentWithCount(); + while (this.tasks.readItem()) |task| { + task.run(context); + } + + this.loop.tickWithoutIdle(); + + if (this.tasks.count == 0 and this.tickConcurrentWithCount() == 0) break; + } + } + pub fn tick( this: *MiniEventLoop, context: *anyopaque, @@ -1748,10 +1766,10 @@ pub const AnyEventLoop = union(enum) { switch (this.*) { .js => { this.js.tick(); - this.js.autoTick(); + this.js.autoTickActive(); }, .mini => { - this.mini.tickOnce(context); + this.mini.tickWithoutIdle(context); }, } } diff --git a/src/install/install.zig b/src/install/install.zig index 4fdf545b45..91d63e966e 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -2162,12 +2162,12 @@ pub const PackageManager = struct { } pub fn tickLifecycleScripts(this: *PackageManager) void { - this.event_loop.tick(this, hasNoMorePendingLifecycleScripts); + this.event_loop.tickOnce(this); } pub fn sleep(this: *PackageManager) void { Output.flush(); - this.event_loop.tickOnce(this); + this.event_loop.tick(this, hasNoMorePendingLifecycleScripts); } const DependencyToEnqueue = union(enum) { @@ -6310,7 +6310,7 @@ pub const PackageManager = struct { }, }; manager.lockfile = try ctx.allocator.create(Lockfile); - + JSC.MiniEventLoop.global = &manager.event_loop.mini; if (!manager.options.enable.cache) { manager.options.enable.manifest_cache = false; manager.options.enable.manifest_cache_control = false; @@ -8860,7 +8860,7 @@ pub const PackageManager = struct { this.sleep(); } else { - this.sleep(); + this.tickLifecycleScripts(); } this.finished_installing.store(true, .Monotonic); diff --git a/src/install/lifecycle_script_runner.zig b/src/install/lifecycle_script_runner.zig index df52e03cbb..40ee577c4c 100644 --- a/src/install/lifecycle_script_runner.zig +++ b/src/install/lifecycle_script_runner.zig @@ -27,6 +27,8 @@ pub const LifecycleScriptSubprocess = struct { timer: ?Timer = null, + pub usingnamespace bun.New(@This()); + pub const min_milliseconds_to_log = 500; pub var alive_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0); @@ -491,17 +493,13 @@ pub const LifecycleScriptSubprocess = struct { pub fn deinit(this: *LifecycleScriptSubprocess) void { this.resetPolls(); - if (this.process) |process| { - this.process = null; - process.detach(); - process.deref(); - } if (!this.manager.options.log_level.isVerbose()) { this.stdout.buffer.clearAndFree(); this.stderr.buffer.clearAndFree(); } - this.manager.allocator.destroy(this); + + this.destroy(); } pub fn spawnPackageScripts( @@ -510,10 +508,12 @@ pub const LifecycleScriptSubprocess = struct { envp: [:null]?[*:0]u8, comptime log_level: PackageManager.Options.LogLevel, ) !void { - var lifecycle_subprocess = try manager.allocator.create(LifecycleScriptSubprocess); - lifecycle_subprocess.scripts = list.items; - lifecycle_subprocess.manager = manager; - lifecycle_subprocess.envp = envp; + var lifecycle_subprocess = LifecycleScriptSubprocess.new(.{ + .manager = manager, + .envp = envp, + .scripts = list.items, + .package_name = list.first().package_name, + }); if (comptime log_level.isVerbose()) { Output.prettyErrorln("[LifecycleScriptSubprocess] Starting scripts for \"{s}\"", .{