Skip to content

Commit

Permalink
always clean callback on deinit
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Apr 12, 2024
1 parent 80e855c commit 19c944a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@ const Handlers = struct {
// will deinit when is not wrapped or when is the TCP wrapped connection
if (wrapped != .tls) {
if (ctx) |ctx_| {
// at this point we dont care about the callback anymore because we are deiniting after this
// ctx will deinit only in the next tick
ctx_.cleanCallbacks(false);
ctx_.deinit(ssl);
}
}
Expand Down Expand Up @@ -842,7 +839,6 @@ pub const Listener = struct {
this.poll_ref.unref(this.handlers.vm);
if (this.handlers.active_connections == 0) {
this.handlers.unprotect();
this.socket_context.?.close(this.ssl);
this.socket_context.?.deinit(this.ssl);
this.socket_context = null;
this.strong_self.clear();
Expand All @@ -866,9 +862,6 @@ pub const Listener = struct {
this.handlers.unprotect();

if (this.socket_context) |ctx| {
// at this point we dont care about the callback anymore because we are deiniting after this
// ctx will deinit only in the next tick
if (this.ssl) ctx.cleanCallbacks(true) else ctx.cleanCallbacks(false);
ctx.deinit(this.ssl);
}

Expand Down
4 changes: 3 additions & 1 deletion src/deps/uws.zig
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ pub const SocketContext = opaque {
us_socket_context_free(@as(i32, 0), this);
}

pub fn cleanCallbacks(ctx: *SocketContext, comptime is_ssl: bool) void {
pub fn cleanCallbacks(ctx: *SocketContext, is_ssl: bool) void {
const ssl_int: i32 = @intFromBool(is_ssl);
// replace callbacks with dummy ones
const DummyCallbacks = struct {
Expand Down Expand Up @@ -943,6 +943,8 @@ pub const SocketContext = opaque {

/// closes and deinit the SocketContexts
pub fn deinit(this: *SocketContext, ssl: bool) void {
// at this point we dont care about the callback anymore because we are deiniting after this
this.cleanCallbacks(ssl);
this.close(ssl);
//always deinit in next iteration
if (ssl) {
Expand Down

0 comments on commit 19c944a

Please sign in to comment.