Skip to content

Commit 802ad42

Browse files
committed
Don't endlessly wait on writer coroutine on disconnect
1 parent 1d61c93 commit 802ad42

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lib/remote/jsonrpcconnection.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,22 @@ void JsonRpcConnection::Disconnect()
256256
IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) {
257257
m_OutgoingMessagesQueued.Set();
258258

259-
m_WriterDone.Wait(yc);
259+
{
260+
Timeout writerTimeout(
261+
m_IoStrand,
262+
boost::posix_time::seconds(5),
263+
[this]() {
264+
// The writer coroutine could not finish soon enough to unblock the waiter down blow,
265+
// so we have to do this on our own, and the coroutine will be terminated forcibly when
266+
// the ops on the underlying socket are cancelled.
267+
boost::system::error_code ec;
268+
m_Stream->lowest_layer().cancel(ec);
269+
}
270+
);
271+
272+
m_WriterDone.Wait(yc);
273+
// We don't need to explicitly cancel the timer here; its destructor will handle it for us.
274+
}
260275

261276
m_CheckLivenessTimer.cancel();
262277
m_HeartbeatTimer.cancel();

0 commit comments

Comments
 (0)