From ab0a292a0eb916170eef755639dc602af4e40c97 Mon Sep 17 00:00:00 2001 From: Michael van der Werve Date: Fri, 8 May 2020 13:20:10 +0200 Subject: [PATCH] file descriptor should not be monitored any more when the tcp connection is destructed. --- src/linux_tcp/tcpconnection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/linux_tcp/tcpconnection.cpp b/src/linux_tcp/tcpconnection.cpp index 651062e..23bb4a1 100644 --- a/src/linux_tcp/tcpconnection.cpp +++ b/src/linux_tcp/tcpconnection.cpp @@ -38,6 +38,12 @@ TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) : */ TcpConnection::~TcpConnection() noexcept { + // if there is still a file descriptor open, we must explicitly unwatch it, otherwise it could + // remain open (tcp connection is forcefully closed). since we assume the handler is in scope for + // the complete lifetime of the tcpconnection, we make one last call to notify it to unmonitor + // the file descriptor. + if (fileno() > 0) _handler->monitor(this, fileno(), 0); + // When the object is destructed, the _state-pointer will also destruct, resulting // in some final calls back to us to inform that the connection has indeed been closed. // This normally results in calls back to user-space (via the _handler pointer) but