versatica / JsSIP

JsSIP, the JavaScript SIP library
https://jssip.net
Other
2.42k stars 744 forks source link

Abnormal session cancellation method under race condition #836

Closed Ga-hou closed 1 month ago

Ga-hou commented 1 year ago

Hi, We have the following situation:

  1. JsSIP clientA send Invite request to server
  2. Invite comes to JsSIP clientB
  3. ClientB answer with 200 OK
  4. JsSIP clientA send Cancel request to server
  5. In the same moment server send 200 OK Message to JsSIP ClientA

The Session is not ended in server and clientB, thus call is hanging until clientB trigger terminate of the session.

I've found the following code whice seems like the reason of the issue:

https://github.com/versatica/JsSIP/blob/master/lib/RTCSession.js#L850

        // Check Session Status.
        if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT)
        {
          this._is_canceled = true;
          this._cancel_reason = cancel_reason;
        }
        else if (this._status === C.STATUS_1XX_RECEIVED)
        {
          this._request.cancel(cancel_reason);
        }

https://github.com/versatica/JsSIP/blob/master/lib/RTCSession.js#L2772

    // Proceed to cancellation if the user requested.
    if (this._is_canceled)
    {
      if (response.status_code >= 100 && response.status_code < 200)
      {
        this._request.cancel(this._cancel_reason);
      }
      else if (response.status_code >= 200 && response.status_code < 299)
      {
        this._acceptAndTerminate(response);
      }

      return;
    }

When JSSIP canceled the operation when the status was 1XX received, is canceled flag was not set to true, which resulted in no ACK and BYE being sent when the subsequent 200 OK was received.

What do you thing about it? Is it a bug or am I wrong in my conclusions?