From d649d682c4d28c1f22b8c106d25d0ad982caeebb Mon Sep 17 00:00:00 2001 From: Joshua Colp Date: Wed, 6 May 2015 15:24:29 -0300 Subject: res_pjsip_exten_state: Fix race condition between sending NOTIFY and termination The res_pjsip_exten_state module currently has a race condition between processing the extension state callback from the PBX core and processing the subscription shutdown callback from res_pjsip_pubsub. There is currently no synchronization between the two. This can present a problem as while the SIP subscription will remain valid the tree it points to may not. This is in particular a problem as a task to send a NOTIFY may get queued which will try to use the tree that may no longer be valid. This change does the following to fix this problem: 1. All access to the subscription tree is done within the task that sends the NOTIFY to ensure that no other thread is modifying or destroying the tree. This task executes on the serializer for the subscriptions. 2. A reference to the subscription serializer is kept to ensure it remains valid for the lifetime of the extension state subscription. 3. The NOTIFY task has been changed so it will no longer attempt to send a NOTIFY if the subscription has already been terminated. ASTERISK-25057 #close Reported by: Matt Jordan Change-Id: I0b3cd2fac5be8d9b3dc5e693aaa79846eeaf5643 --- include/asterisk/res_pjsip_pubsub.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/asterisk/res_pjsip_pubsub.h b/include/asterisk/res_pjsip_pubsub.h index d32b246af..afa0d6930 100644 --- a/include/asterisk/res_pjsip_pubsub.h +++ b/include/asterisk/res_pjsip_pubsub.h @@ -405,6 +405,16 @@ void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char */ const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub); +/*! + * \brief Get whether the subscription has been terminated or not. + * + * \param sub The subscription. + * \retval 0 not terminated. + * \retval 1 terminated. + * \since 13.4.0 + */ +int ast_sip_subscription_is_terminated(const struct ast_sip_subscription *sub); + /*! * \brief Get a header value for a subscription. * -- cgit v1.2.3