From eb98e518673ce5dba02a87d4df1728148c4053e6 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 15 Sep 2025 00:07:09 -0400 Subject: [PATCH] We expect to get valid fds to close in ~Connection in ~Server --- src/connection.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/connection.cpp b/src/connection.cpp index 22e24d4..1be9328 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -59,7 +59,14 @@ Connection::Connection(struct sockaddr_storage addr, int fd, int64_t id, Connection::~Connection() { handler_->on_connection_closed(*this); - assert(fd_ < 0 && "Connection fd was not closed before ~Connection"); + if (fd_ >= 0) { + int e = ::close(fd_); + if (e == -1 && errno != EINTR) { + perror("close"); + std::abort(); + } + // EINTR ignored - fd is guaranteed closed on Linux + } } void Connection::close() {