It took us some time to reproduce. Here is what we see…
When we unregister the client and Asterisk removes the subscription we see the following:
[2024-07-02 11:49:48] DEBUG[2482351] res_pjsip_pubsub.c: Removing subscription 'GT251->DND_251' from list of subscriptions
[2024-07-02 11:49:48] DEBUG[2482351] res_pjsip_pubsub.c: Removing subscription 0x7f941511c530 'GT251->DND_251' reference to subscription tree 0x7f9415b56e10
[2024-07-02 11:49:48] DEBUG[2482351] res_pjsip_pubsub.c: Destroying subscription tree 0x7f9415b56e10 'GT251->DND_251'
[2024-07-02 11:49:48] DEBUG[2482351] res_pjsip_pubsub.c: Destroying SIP subscription from 'GT251->DND_251'
When we unresgiter and asterisk fails to remove the subscription, we see:
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: evsub 0x7f9449c6a7e8 state TERMINATED event TSX_STATE sub_tree 0x7f948082aff0 sub_tree state Normal
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: Subscription ending, do nothing.
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: evsub 0x7f9449c6a7e8 sub_tree 0x7f948082aff0 sub_tree state Normal
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: Updating persistence for 'GT251->DND_251' prune on boot: no
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: sub_tree 0x7f948082aff0 sub_tree state TerminatePending
[2024-07-02 11:38:56] DEBUG[169457] res_pjsip_pubsub.c: Updating persistence for 'GT251->DND_251' prune on boot: no
Here’s is our theory.
We looked in github for the Subscription ending, do nothing
and it is referenced here:
Looking at that function, if we understand it correctly, Asterisk will not remove the subscription if there is a pending NOTIFY.
Looking at the SIP capture we actually see that this is the case.
(We use Kamailio as an edge)
Asterisk removed the subscription, you can see the NOTIFY after the SUBSCRIBE with Expire of 0:
Asterisk failed to remove the subscription, no NOTIFY sent after the Exp 0:
So, it seems, that for whatever reason, Asterisk caches that NOTIFY but can’t sent it because the endpoint is no longer active, but since there is an active (cached) NOTIFY waiting to be sent, Asterisk is not removing the subscription even it is expired.
Please let me know if you need any further information