From 19c944a89a5d00e1d37c256d1ccc53a985314060 Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Thu, 11 Apr 2024 23:51:09 -0300 Subject: [PATCH] always clean callback on deinit --- src/bun.js/api/bun/socket.zig | 7 ------- src/deps/uws.zig | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 42b056c4acd41..35ddcfaeaabb5 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -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); } } @@ -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(); @@ -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); } diff --git a/src/deps/uws.zig b/src/deps/uws.zig index d8bd44173b9d9..42680e81673c9 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -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 { @@ -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) {