Don't endlessly wait on writer coroutine on disconnect

This commit is contained in:
Yonas Habteab 2024-11-28 11:06:44 +01:00
parent f2fbb61ad8
commit 7b30cb3431

View File

@ -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();