File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,17 @@ void JsonRpcConnection::Disconnect()
213
213
IoEngine::SpawnCoroutine (m_IoStrand, [this , keepAlive](asio::yield_context yc) {
214
214
m_OutgoingMessagesQueued.Set ();
215
215
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
+ }
217
227
218
228
/*
219
229
* Do not swallow exceptions in a coroutine.
@@ -228,6 +238,8 @@ void JsonRpcConnection::Disconnect()
228
238
m_CheckLivenessTimer.cancel ();
229
239
m_HeartbeatTimer.cancel ();
230
240
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.
231
243
m_Stream->lowest_layer ().cancel (ec);
232
244
233
245
Timeout::Ptr shutdownTimeout (new Timeout (
You can’t perform that action at this time.
0 commit comments