Close all cdp clients on shutdown

This commit is contained in:
Nikolay Govorov
2026-03-17 10:59:35 +00:00
parent 9a055a61a6
commit 586413357e
3 changed files with 11 additions and 9 deletions

View File

@@ -64,17 +64,17 @@ pub fn init(app: *App, address: net.Address) !*Server {
return self; return self;
} }
pub fn deinit(self: *Server) void { pub fn shutdown(self: *Server) void {
// Stop all active clients self.client_mutex.lock();
{ defer self.client_mutex.unlock();
self.client_mutex.lock();
defer self.client_mutex.unlock();
for (self.clients.items) |client| { for (self.clients.items) |client| {
client.stop(); client.stop();
}
} }
}
pub fn deinit(self: *Server) void {
self.shutdown();
self.joinThreads(); self.joinThreads();
self.clients.deinit(self.allocator); self.clients.deinit(self.allocator);
self.clients_pool.deinit(); self.clients_pool.deinit();

View File

@@ -115,6 +115,8 @@ fn run(allocator: Allocator, main_arena: Allocator) !void {
}; };
defer server.deinit(); defer server.deinit();
try sighandler.on(lp.Server.shutdown, .{server});
app.network.run(); app.network.run();
}, },
.fetch => |opts| { .fetch => |opts| {

View File

@@ -491,7 +491,7 @@ fn acceptConnections(self: *Runtime) void {
error.ConnectionAborted => { error.ConnectionAborted => {
lp.log.warn(.app, "accept connection aborted", .{}); lp.log.warn(.app, "accept connection aborted", .{});
continue; continue;
}, },
else => { else => {
lp.log.err(.app, "accept error", .{ .err = err }); lp.log.err(.app, "accept error", .{ .err = err });
continue; continue;