From 132a23354e0019c681934edca69c30e50c495cf8 Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Thu, 20 Dec 2018 09:29:36 +0800 Subject: [PATCH] Fix pending callback not called when ServerConnection destructs (#3572) --- src/ray/common/client_connection.cc | 8 ++++++++ src/ray/common/client_connection.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/ray/common/client_connection.cc b/src/ray/common/client_connection.cc index 1ae225443..db7caaeb6 100644 --- a/src/ray/common/client_connection.cc +++ b/src/ray/common/client_connection.cc @@ -33,6 +33,14 @@ ServerConnection::ServerConnection(boost::asio::basic_stream_socket &&sock async_write_queue_(), async_write_in_flight_(false) {} +template +ServerConnection::~ServerConnection() { + // If there are any pending messages, invoke their callbacks with an IOError status. + for (const auto &write_buffer : async_write_queue_) { + write_buffer->handler(Status::IOError("Connection closed.")); + } +} + template Status ServerConnection::WriteBuffer( const std::vector &buffer) { diff --git a/src/ray/common/client_connection.h b/src/ray/common/client_connection.h index d4ca993d2..7246c2b81 100644 --- a/src/ray/common/client_connection.h +++ b/src/ray/common/client_connection.h @@ -29,6 +29,9 @@ ray::Status TcpConnect(boost::asio::ip::tcp::socket &socket, template class ServerConnection : public std::enable_shared_from_this> { public: + /// ServerConnection destructor. + virtual ~ServerConnection(); + /// Allocate a new server connection. /// /// \param socket A reference to the server socket.