Hi everyone,
I wanted to share an approach I’ve been exploring in VoIPBin that might be helpful to others working with Asterisk and SIP.
VoIPBin(https://voipbin.net) is an open-source CPaaS (Communications Platform as a Service) project I’ve been developing on my own. It supports voice, SMS, email, and AI features — but in this post, I’d like to focus on voice and a problem that has been on my mind for quite some time: recovering SIP sessions after an Asterisk crash.
This is not a new problem; it’s something I’ve been considering for years. After many attempts and quite a bit of trial and error, I’ve arrived at a method that seems to work in certain cases. Of course, this may not be the definitive solution, and there might be better, more robust methods out there already. If anyone knows of better approaches, I would be very grateful to learn about them.
The Problem
When Asterisk crashes during an active call, all SIP dialogs immediately disappear. From the client’s perspective, the session vanishes without any BYE or cleanup signals, which results in confusing call drops and broken media streams.
The Goal
To restore the SIP session so that the client perceives it as a continuation of the original call rather than a new one.
The Approach
- Crash detection: VoIPBin’s sentinel-manager detects the crash.
- Session lookup: Active call sessions handled by the crashed instance are queried from the database.
- SIP info retrieval: Using HOMER, recent signaling data is analyzed to extract SIP headers (Call-ID, tags, etc.).
- New SIP channel creation: A new SIP channel is created on a healthy Asterisk instance.
- Set recovery variables: Channel variables override From/To URIs, tags, Call-ID, and CSeq to match the original dialog.
- Send recovery INVITE: This INVITE acts like a re-INVITE, using the original dialog identifiers.
- Session resumes: If the client accepts, the SIP session is resumed.
- Flow continues: VoIPBin resumes the call flow, whether it’s a direct call or conference.
To enable this, I patched the PJSIP stack in Asterisk to allow channel variables to override key SIP headers. The patch is available here:
etc/asterisk/add_pjsip_recovery.patch at main · voipbin/etc · GitHub
A more detailed explanation and demo can be found here:
Architecture — voipbin documentation
Limitations
- This method relies entirely on the SIP endpoint (UAC/UAS) supporting mid-dialog re-INVITE.
- Some clients — Linphone, for example — reject such re-INVITEs, so recovery does not work in those cases.
- If the endpoint refuses the recovery INVITE, the session cannot be restored.
Closing Thoughts
This is definitely not a perfect solution, and I’m not sure how well it will work beyond the limited environments I’ve tested. I’m sharing it simply in case it provides someone else with a useful idea or a direction to explore further. If there are better or more robust solutions out there, I’d be eager to learn from them.
Thanks for reading,
Sungtae
Asterisk #VoIP #SIP #CrashRecovery #CPaaS #OpenSource #VoIPBin