transport: Fix segfault when transport is closed while multiple send operations are scheduled
Change-Id: Icf6158150c9b6c2c17a89c01fc883eaf003e356e
Refs: #3136
diff --git a/src/transport/stream-transport.hpp b/src/transport/stream-transport.hpp
index 99dc510..5ec91b0 100644
--- a/src/transport/stream-transport.hpp
+++ b/src/transport/stream-transport.hpp
@@ -195,6 +195,10 @@
BOOST_THROW_EXCEPTION(Transport::Error(error, "error while sending data to socket"));
}
+ if (!m_transport.m_isConnected) {
+ return; // queue has been already cleared
+ }
+
m_transmissionQueue.erase(queueItem);
if (!m_transmissionQueue.empty()) {
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index b166edf..3a5f071 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -496,6 +496,21 @@
BOOST_CHECK_EQUAL(nTimeouts, 4);
}
+BOOST_AUTO_TEST_CASE(ShutdownWhileSendInProgress) // Bug #3136
+{
+ Face face;
+ face.expressInterest(Name("/Hello/World/!"), bind([]{}), bind([]{}));
+ BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1)));
+
+ face.expressInterest(Name("/Bye/World/1"), bind([]{}), bind([]{}));
+ face.expressInterest(Name("/Bye/World/2"), bind([]{}), bind([]{}));
+ face.expressInterest(Name("/Bye/World/3"), bind([]{}), bind([]{}));
+ face.shutdown();
+
+ BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1)));
+ // should not segfault
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // tests