Fix pending callback not called when ServerConnection destructs (#3572)

This commit is contained in:
Hao Chen 2018-12-20 09:29:36 +08:00 committed by Robert Nishihara
parent ffa6ee3ec8
commit 132a23354e
2 changed files with 11 additions and 0 deletions

View file

@ -33,6 +33,14 @@ ServerConnection<T>::ServerConnection(boost::asio::basic_stream_socket<T> &&sock
async_write_queue_(), async_write_queue_(),
async_write_in_flight_(false) {} async_write_in_flight_(false) {}
template <class T>
ServerConnection<T>::~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 <class T> template <class T>
Status ServerConnection<T>::WriteBuffer( Status ServerConnection<T>::WriteBuffer(
const std::vector<boost::asio::const_buffer> &buffer) { const std::vector<boost::asio::const_buffer> &buffer) {

View file

@ -29,6 +29,9 @@ ray::Status TcpConnect(boost::asio::ip::tcp::socket &socket,
template <typename T> template <typename T>
class ServerConnection : public std::enable_shared_from_this<ServerConnection<T>> { class ServerConnection : public std::enable_shared_from_this<ServerConnection<T>> {
public: public:
/// ServerConnection destructor.
virtual ~ServerConnection();
/// Allocate a new server connection. /// Allocate a new server connection.
/// ///
/// \param socket A reference to the server socket. /// \param socket A reference to the server socket.