Skip to content

Commit

Permalink
fix(install): ensure capacity of preinstall_state before cleaning l…
Browse files Browse the repository at this point in the history
…ockfile (#11792)

Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
dylan-conway and Jarred-Sumner committed Jun 11, 2024
1 parent 6e0f58b commit bd6a605
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/bun.js/bindings/webcore/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,12 @@ void WebSocket::didClose(unsigned unhandledBufferedAmount, unsigned short code,
// so we just call decPendingActivityCount() after dispatching the event
ASSERT(m_pendingActivityCount > 0);


if (this->hasEventListeners("close"_s)) {
this->dispatchEvent(CloseEvent::create(wasClean, code, reason));

// we deinit if possible in the next tick
if (auto* context = scriptExecutionContext()) {
context->postTask([this, code, wasClean, reason, protectedThis = Ref { *this }](ScriptExecutionContext& context) {
context->postTask([this, protectedThis = Ref { *this }](ScriptExecutionContext& context) {
ASSERT(scriptExecutionContext());
protectedThis->decPendingActivityCount();
});
Expand Down
6 changes: 3 additions & 3 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3232,19 +3232,19 @@ pub const PackageManager = struct {
}
}

fn ensurePreinstallStateListCapacity(this: *PackageManager, count: usize) !void {
pub fn ensurePreinstallStateListCapacity(this: *PackageManager, count: usize) void {
if (this.preinstall_state.items.len >= count) {
return;
}

const offset = this.preinstall_state.items.len;
try this.preinstall_state.ensureTotalCapacity(this.allocator, count);
this.preinstall_state.ensureTotalCapacity(this.allocator, count) catch bun.outOfMemory();
this.preinstall_state.expandToCapacity();
@memset(this.preinstall_state.items[offset..], PreinstallState.unknown);
}

pub fn setPreinstallState(this: *PackageManager, package_id: PackageID, lockfile: *Lockfile, value: PreinstallState) void {
this.ensurePreinstallStateListCapacity(lockfile.packages.len) catch return;
this.ensurePreinstallStateListCapacity(lockfile.packages.len);
this.preinstall_state.items[package_id] = value;
}

Expand Down
5 changes: 4 additions & 1 deletion src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,10 @@ pub fn cleanWithLogger(
// never grow

// preinstall_state is used during installPackages. the indexes(package ids) need
// to be remapped
// to be remapped. Also ensure `preinstall_state` has enough capacity to contain
// all packages. It's possible it doesn't because non-npm packages do not use
// preinstall state before linking stage.
manager.ensurePreinstallStateListCapacity(old.packages.len);
var preinstall_state = manager.preinstall_state;
var old_preinstall_state = preinstall_state.clone(old.allocator) catch bun.outOfMemory();
defer old_preinstall_state.deinit(old.allocator);
Expand Down

0 comments on commit bd6a605

Please sign in to comment.