Skip to content

Commit

Permalink
Don't endlessly wait on writer coroutine on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jan 13, 2025
1 parent f2fbb61 commit 7b30cb3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/remote/jsonrpcconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,22 @@ void JsonRpcConnection::Disconnect()
IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) {
m_OutgoingMessagesQueued.Set();

m_WriterDone.Wait(yc);
{
Timeout writerTimeout(
m_IoStrand,
boost::posix_time::seconds(5),
[this]() {
// The writer coroutine could not finish soon enough to unblock the waiter down blow,
// so we have to do this on our own, and the coroutine will be terminated forcibly when
// the ops on the underlying socket are cancelled.
boost::system::error_code ec;
m_Stream->lowest_layer().cancel(ec);
}
);

m_WriterDone.Wait(yc);
// We don't need to explicitly cancel the timer here; its destructor will handle it for us.
}

m_CheckLivenessTimer.cancel();
m_HeartbeatTimer.cancel();
Expand Down

0 comments on commit 7b30cb3

Please sign in to comment.