Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
f5a29e4f1e Attempt to fix crash during thread exit on Windows 2024-10-29 13:57:06 -07:00
2 changed files with 16 additions and 1 deletions

View File

@@ -1245,7 +1245,7 @@ pub const HTTPThread = struct {
@compileError("TODO:");
}
while (true) {
while (!bun.Global.isExiting()) {
this.drainEvents();
var start_time: i128 = 0;
@@ -1265,6 +1265,8 @@ pub const HTTPThread = struct {
Output.flush();
}
}
bun.exitThread();
}
pub fn scheduleShutdown(this: *@This(), http: *AsyncHTTP) void {

View File

@@ -30,6 +30,19 @@ pub fn main() void {
@ptrCast(&bun.Mimalloc.mi_calloc),
@ptrCast(&bun.Mimalloc.mi_free),
);
// This memory gets freed when the main thread exits
// if the main thread exits before the other threads, the other threads will segfault.
var string_builder = bun.StringBuilder{};
const environ_count = std.os.environ.len;
for (std.os.environ) |arg| {
string_builder.countZ(std.mem.sliceTo(arg, 0));
}
string_builder.allocate(bun.default_allocator) catch Output.panic("Bun is unable to allocate memory.", .{});
const out_environ = bun.default_allocator.alloc([*:0]u8, environ_count) catch Output.panic("Bun is unable to allocate memory.", .{});
for (std.os.environ, out_environ) |arg, *out| {
out.* = @constCast(string_builder.appendZ(std.mem.sliceTo(arg, 0)));
}
std.os.environ = out_environ;
environ = @ptrCast(std.os.environ.ptr);
_environ = @ptrCast(std.os.environ.ptr);
}