SIP: BYE vs CANCEL Methods

Krishnakumar PG
3 min readMay 29, 2024

--

In today’s article, let’s dive into the differences and use-cases of BYE and CANCEL methods. In short, both BYE and CANCEL request methods are used to terminate a session, but the key distinction lies in when they are used.

The BYE method is designed to terminate an existing SIP session that was established using an INVITE method. It is used to disconnect a call that has already been answered and is in progress. On the other hand, the CANCEL method is used when termination occurs before the callee has successfully answered. CANCEL can be used at any stage of the call setup process, while BYE is only used for calls that have already been answered.

Ending an active session using BYE

In the SIP flow diagram below, we can see that the INVITE message from caller was responded with 100 Trying to acknowledge reliable delivery of the INVITE request, then a 180 Ringing and a 200 OK making it a successful session between the caller and callee.

Ending an active session with BYE

As we can see, there are three transactions when the call was successfully completed and then terminated using a BYE request.

  • Transaction 1: INVITE, 180 Ringing and 200 OK
  • Transaction 2: ACK

ACK is a transaction by itself on a successful session.

  • Transaction 3: BYE, and its 200 OK.

The INVITE transaction was completed successfully with a 200 OK response from the callee. After completing media transmission, the call was torn down using a BYE request.

CANCEL’ing an ongoing request

CANCEL is specifically designed to cancel a pending INVITE or UPDATE request. In this flow diagram below, we can see that the caller sends a CANCEL message before a 200 OK was sent by the callee for the pending INVITE request. The caller’s intent is to CANCEL the INVITE request it had sent previously.

CANCEL’ed SIP Call

We can see two transactions when the caller hung up before callee answered.

  • Transaction 1: INVITE, 180 Ringing, 487 Request Terminated, ACK.

Yes, ACK is a spoilt brat when it comes to SIP. It is seen as a separate transaction only after a success response and not after a failure response (487 Request terminated in this example).

  • Transaction 2: CANCEL, 200 OK.

As we can see, the initial INVITE was responded with 100 Trying to acknowledge reliable delivery, then a 180 ringing. When the call was ringing, caller sends a CANCEL request to cancel its invitation. Then the callee responds to the CANCEL with a 200 OK to let the caller know that the INVITE request will be cancelled. Then the INVITE transaction is completed with a 487 Request Terminated final response.

Conclusion

In conclusion, understanding the difference between BYE and CANCEL methods in SIP is crucial for efficient and reliable communication. By recognizing when to use each method, developers and network administrators can optimize system handling of session termination scenarios. This article has explored the intricacies of SIP protocol, highlighting the distinct roles of BYE and CANCEL methods. Staying up-to-date on these subtleties ensures seamless communication in a rapidly evolving technology landscape.

Happy SIP’ing.

--

--