From 2ce50b33a5d8a1e742bdff5722690004f067a4e0 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 21 Nov 2024 10:43:22 -0500 Subject: [PATCH] fix for #386 --- src/request-handler.cpp | 8 +++++++- src/sip-dialog-controller.cpp | 3 +++ src/sip-dialog.cpp | 20 +++++++++++++------- src/sip-dialog.hpp | 27 +++++++++++++++++---------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/request-handler.cpp b/src/request-handler.cpp index 9a68baf72e..90edac8e57 100644 --- a/src/request-handler.cpp +++ b/src/request-handler.cpp @@ -438,7 +438,13 @@ namespace drachtio { m_thread.swap( t ) ; } RequestHandler::~RequestHandler() { - curl_multi_cleanup(m_g.multi); + if (nullptr == m_g.multi) { + DR_LOG(log_error) << "RequestHandler::~RequestHandler - multi handle is null; this should only happen during shutdown"; + } + else { + curl_multi_cleanup(m_g.multi); + m_g.multi = nullptr; + } } void RequestHandler::threadFunc() { diff --git a/src/sip-dialog-controller.cpp b/src/sip-dialog-controller.cpp index 56ae0466bc..36a5fc809e 100644 --- a/src/sip-dialog-controller.cpp +++ b/src/sip-dialog-controller.cpp @@ -346,6 +346,9 @@ namespace drachtio { if( orq ) { DR_LOG(log_info) << "SipDialogController::doSendRequestInsideDialog - created orq " << std::hex << (void *) orq << " sending " << nta_outgoing_method_name(orq) << " to " << requestUri ; + if( sip_method_invite == method ) { + dlg->addReinviteOrq(orq); + } } } diff --git a/src/sip-dialog.cpp b/src/sip-dialog.cpp index d93795385c..15f3c946cb 100644 --- a/src/sip-dialog.cpp +++ b/src/sip-dialog.cpp @@ -199,8 +199,8 @@ namespace drachtio { nta_leg_t *leg = nta_leg_by_call_id( theOneAndOnlyController->getAgent(), getCallId().c_str() ); - DR_LOG(log_debug) << "SipDialog::~SipDialog - I'm holding leg " << std::hex << (void *) m_leg << - " and retrieved leg via call-id " << (void *) leg; + DR_LOG(log_debug) << "SipDialog::~SipDialog - I'm holding leg " << std::hex << (void *) m_leg << + " and retrieved leg via call-id " << (void *) leg; assert( leg ) ; if( leg ) { @@ -214,6 +214,12 @@ namespace drachtio { if (we_are_uac == m_type && m_orq) { theOneAndOnlyController->getDialogController()->stopTimerD(m_orq); } + + for (nta_outgoing_t* item : m_reinvites) { + DR_LOG(log_debug) << "SipDialog::~SipDialog - I'm holding a reinvite orq " << std::hex << (void *) item; + theOneAndOnlyController->getDialogController()->stopTimerD(item); + } + /* N.B.: we only destroy the orq here for ACK for non-udp transports, since timer D handles for udp */ if (m_orqAck && m_bDestroyAckOnClose) { DR_LOG(log_debug) << "SipDialog::~SipDialog - destroying orq from original (uac) ACK " << std::hex << (void *) m_orqAck ; @@ -223,11 +229,11 @@ namespace drachtio { nta_outgoing_destroy(m_orq); } - auto txnIds = getIncomingRequestTransactionIds(); - theOneAndOnlyController->getDialogController()->clearDanglingIncomingRequests(txnIds); - - /* if we never got an ACK after sending a 200 OK to an incoming INVITE the net transaction is still there */ - theOneAndOnlyController->getClientController()->removeNetTransaction(this->getTransactionId()); + auto txnIds = getIncomingRequestTransactionIds(); + theOneAndOnlyController->getDialogController()->clearDanglingIncomingRequests(txnIds); + + /* if we never got an ACK after sending a 200 OK to an incoming INVITE the net transaction is still there */ + theOneAndOnlyController->getClientController()->removeNetTransaction(this->getTransactionId()); } std::ostream& operator<<(std::ostream& os, const SipDialog& dlg) { diff --git a/src/sip-dialog.hpp b/src/sip-dialog.hpp index 572f5f5028..8152d66e59 100644 --- a/src/sip-dialog.hpp +++ b/src/sip-dialog.hpp @@ -219,15 +219,19 @@ namespace drachtio { uint32_t getSeq(void) { return m_seq; } void clearSeq(void) {m_seq = 0;} - void addIncomingRequestTransaction(std::string& txnId) { - m_incomingRequestTransactionIds.insert(txnId); - } - void removeIncomingRequestTransaction(std::string& txnId) { - m_incomingRequestTransactionIds.erase(txnId); - } - std::vector getIncomingRequestTransactionIds(void) { - return std::vector(m_incomingRequestTransactionIds.begin(), m_incomingRequestTransactionIds.end()); - } + void addIncomingRequestTransaction(std::string& txnId) { + m_incomingRequestTransactionIds.insert(txnId); + } + void removeIncomingRequestTransaction(std::string& txnId) { + m_incomingRequestTransactionIds.erase(txnId); + } + std::vector getIncomingRequestTransactionIds(void) { + return std::vector(m_incomingRequestTransactionIds.begin(), m_incomingRequestTransactionIds.end()); + } + + void addReinviteOrq(nta_outgoing_t* orq) { + m_reinvites.push_back(orq); + } protected: @@ -291,7 +295,10 @@ namespace drachtio { // arrival time sip_time_t m_tmArrival; - std::set m_incomingRequestTransactionIds; + std::set m_incomingRequestTransactionIds; + + // re-invite orqs that we send as + std::vector m_reinvites; } ;