Skip to content

Commit aef6148

Browse files
committed
Ignore ConnectionClosed error on server shutdown
Our shutdown could be cleaner, but this at least removes a meaningless (because we're shutting down) log.err that was happening on every test run.
1 parent 431db85 commit aef6148

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/server.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const MAX_MESSAGE_SIZE = 512 * 1024 + 14 + 140;
4040

4141
pub const Server = struct {
4242
app: *App,
43+
shutdown: bool,
4344
allocator: Allocator,
4445
client: ?posix.socket_t,
4546
listener: ?posix.socket_t,
@@ -54,16 +55,20 @@ pub const Server = struct {
5455
.app = app,
5556
.client = null,
5657
.listener = null,
58+
.shutdown = false,
5759
.allocator = allocator,
5860
.json_version_response = json_version_response,
5961
};
6062
}
6163

6264
pub fn deinit(self: *Server) void {
63-
self.allocator.free(self.json_version_response);
65+
self.shutdown = true;
6466
if (self.listener) |listener| {
6567
posix.close(listener);
6668
}
69+
// *if* server.run is running, we should really wait for it to return
70+
// before existing from here.
71+
self.allocator.free(self.json_version_response);
6772
}
6873

6974
pub fn run(self: *Server, address: net.Address, timeout_ms: i32) !void {
@@ -82,6 +87,9 @@ pub const Server = struct {
8287
log.info(.app, "server running", .{ .address = address });
8388
while (true) {
8489
const socket = posix.accept(listener, null, null, posix.SOCK.NONBLOCK) catch |err| {
90+
if (self.shutdown) {
91+
return;
92+
}
8593
log.err(.app, "CDP accept", .{ .err = err });
8694
std.time.sleep(std.time.ns_per_s);
8795
continue;

0 commit comments

Comments
 (0)