From 5cbd5cbe428e02408da4615377b47ea37c28a550 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Mon, 30 Jan 2017 12:20:05 -0500
Subject: [PATCH] sip-tls: do not shutdown tls session at pjsip shutdown

It could be counter-intuitive but it's a bad idea to
shutdown the tls session at shutdown pjsip event.
This event is due to the call of pjsip_transport_shutdown()
function. Its documentation indicates that objects
having a session lock on the transport can continue to send
and receive from the transport but new lock can't be obtained.
So, we need to continue tls IO after this event.

This also gives a chance to some msg to be sent, like BYE request.

Change-Id: Ifa82469ec416652f26c240a42c55a284e1887040
Tuleap: #64
---
 src/ringdht/sips_transport_ice.cpp | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/ringdht/sips_transport_ice.cpp b/src/ringdht/sips_transport_ice.cpp
index 23fee8e04d..f4488de4fe 100644
--- a/src/ringdht/sips_transport_ice.cpp
+++ b/src/ringdht/sips_transport_ice.cpp
@@ -200,19 +200,10 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt,
     };
     base.do_shutdown = [](pjsip_transport *transport) -> pj_status_t {
         auto& this_ = reinterpret_cast<TransportData*>(transport)->self;
-        RING_DBG("SipsIceTransport@%p: shutdown", this_);
-        {
-            // Flush pending state changes and rx packet before shutdown
-            // or pjsip callbacks will crash
-
-            std::lock_guard<std::mutex> lk{this_->stateChangeEventsMutex_};
-            this_->stateChangeEvents_.clear();
-
-            std::lock_guard<std::mutex> lk2(this_->rxMtx_);
-            this_->rxPending_.clear();
-
-            this_->tls_->shutdown();
-        }
+        RING_DBG("SipsIceTransport@%p {tr=%p {rc=%ld}}: shutdown", this_,
+                 transport, pj_atomic_get(transport->ref_cnt));
+        // Nothing to do here, tls session is not shutdown as some messages could be pending
+        // and application can continue to do IO (if they already own the transport)
         return PJ_SUCCESS;
     };
     base.destroy = [](pjsip_transport *transport) -> pj_status_t {
-- 
GitLab