summaryrefslogtreecommitdiff
path: root/res/res_pjsip_pubsub.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-05-06 15:24:29 -0300
committerJoshua Colp <jcolp@digium.com>2015-05-07 09:32:58 -0300
commitd649d682c4d28c1f22b8c106d25d0ad982caeebb (patch)
treea5d214c6e3612e39402af9d583c5c0bdf48ccedf /res/res_pjsip_pubsub.c
parent9322bc6ff6157f730a82d5c52259f899028c052c (diff)
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
Diffstat (limited to 'res/res_pjsip_pubsub.c')
-rw-r--r--res/res_pjsip_pubsub.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index bd40a197f..74a3f1985 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -2185,6 +2185,11 @@ const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *
return sub->resource;
}
+int ast_sip_subscription_is_terminated(const struct ast_sip_subscription *sub)
+{
+ return sub->subscription_state == PJSIP_EVSUB_STATE_TERMINATED ? 1 : 0;
+}
+
static int sip_subscription_accept(struct sip_subscription_tree *sub_tree, pjsip_rx_data *rdata, int response)
{
pjsip_hdr res_hdr;