File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -213,7 +213,17 @@ void JsonRpcConnection::Disconnect()
213213 IoEngine::SpawnCoroutine (m_IoStrand, [this , keepAlive](asio::yield_context yc) {
214214 m_OutgoingMessagesQueued.Set ();
215215
216- m_WriterDone.Wait (yc);
216+ {
217+ asio::deadline_timer writerTimeout (m_IoStrand.context (), boost::posix_time::seconds (5 ));
218+ writerTimeout.async_wait (asio::bind_executor (m_IoStrand, [this ](boost::system::error_code ec) {
219+ if (!ec) {
220+ m_WriterDone.Set ();
221+ }
222+ }));
223+
224+ m_WriterDone.Wait (yc);
225+ // We don't need to explicitly cancel the timer here; its destructor will handle it for us.
226+ }
217227
218228 /*
219229 * Do not swallow exceptions in a coroutine.
@@ -228,6 +238,8 @@ void JsonRpcConnection::Disconnect()
228238 m_CheckLivenessTimer.cancel ();
229239 m_HeartbeatTimer.cancel ();
230240
241+ // In case the writer coroutine is not done yet which might got stuck somewhere in async_write
242+ // or async_flush, cancel all operations on the underlying socket to unblock it.
231243 m_Stream->lowest_layer ().cancel (ec);
232244
233245 Timeout::Ptr shutdownTimeout (new Timeout (
You can’t perform that action at this time.
0 commit comments