Skip to content

Notifier: 489/400 to incoming SUBSCRIBE, final NOTIFY on UA.stop() - #980

Open
neutrino38 wants to merge 4 commits into
versatica:masterfrom
neutrino38:notifier-incoming-subscribe
Open

neutrino38 wants to merge 4 commits into
versatica:masterfrom
neutrino38:notifier-incoming-subscribe

Conversation

@neutrino38

Copy link
Copy Markdown
Contributor

Why

  • Without a newSubscribe listener, an incoming SUBSCRIBE gets 405 Method Not Allowed, even though SUBSCRIBE appears in the Allow header of
    that same response. What is unsupported is the event package, which is what 489 Bad Event says (RFC 6665 4.2.1.1).
  • A malformed SUBSCRIBE (no Contact, no Event, invalid Expires) also gets 405. It is a malformed request: 400 Bad Request.
  • UA.stop() leaves the subscriptions we serve open. Subscribers learn we are gone only when their subscription expires.
  • IncomingRequest.reply() is not declared, although every newSubscribe listener has to call it, so TypeScript users must cast the request.

What

  • UA.receiveRequest(): an incoming SUBSCRIBE with no listener gets 489 instead of 405.
  • Notifier.init_incoming(): a malformed SUBSCRIBE gets 400 instead of 405.
  • UA.stop() sends a final NOTIFY (Subscription-State: terminated) for every active Notifier, before the UA is closed. The UA tracks
    notifiers through newNotifier() and destroyNotifier(), as it does for sessions. A fetch SUBSCRIBE (Expires: 0) is not tracked, since it is
    already over. The final NOTIFY carries no reason, so subscribers may re-subscribe whenever they want (RFC 6665 4.1.3).
  • SIPMessage.d.ts now declares IncomingRequest.reply().

Behaviour changes

The response code becomes 489 or 400 where it used to be 405. Applications that already call notifier.terminate() before ua.stop() are
unaffected, because terminate() is idempotent.

Tests

src/test/test-Notifier.ts covers three cases: 489 without a listener, 400 on a SUBSCRIBE with no Event header, and the final NOTIFY on
UA.stop(). All three fail without this change. npm test and npm run lint pass.

- Without a `newSubscribe` listener, an incoming SUBSCRIBE got 405
  Method Not Allowed, although SUBSCRIBE is in the Allow header of that
  very response. What is missing is the event package: 489 Bad Event
  (RFC 6665 4.2.1.1).
- A SUBSCRIBE without Contact or Event, or with a bad Expires, got 405
  too; it is a malformed request: 400 Bad Request.
- UA.stop() ends every Notifier with a final NOTIFY
  (Subscription-State: terminated), sent before the UA is closed, as it
  does for sessions. Subscribers no longer wait for the subscription to
  expire to learn that we are gone.
- IncomingRequest.reply() is declared: every `newSubscribe` listener
  calls it, and had to cast the request to do so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmillan

jmillan commented Oct 2, 2026

Copy link
Copy Markdown
Member

Can you please add the test to the existing test-SubscribeNotifier.ts file?

As asked in the review: the tests now live in the existing file and use
LoopSocket with a real Subscriber instead of a dedicated ResponderSocket.
LoopSocket.pair() links two UAs, since a stopped UA cannot be its own
subscriber.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@neutrino38

Copy link
Copy Markdown
Contributor Author

It's done

Comment thread src/Notifier.js Outdated
this.receiveRequest(this._initial_subscribe);

// A fetch (Expires: 0) is already over.
if (this._state !== C.STATE_TERMINATED) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition always matches. Few lines above (221) stated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition does not always match. receiveRequest() runs between the guard at the top of start() and this check, and it can terminate the notifier: for a fetch
(Expires: 0) it calls _terminateDialog(), so the state is already STATE_TERMINATED here.

Your comment still pointed at a weak spot. After merging master, receiveRequest() can also reply 400 and return when the SUBSCRIBE cannot establish a dialog. The state is then not terminated, so the notifier was registered in the UA without a dialog.

I now test the dialog instead of the state:

  // receiveRequest() leaves no dialog when the SUBSCRIBE is a fetch
  // (Expires: 0), already over, or when it could not establish one.
  if (this._dialog) {
      this._ua.newNotifier(this);
  }

This covers both cases: only a notifier with a live dialog is registered, and UA.stop() only sends a final NOTIFY for those.

@jmillan

jmillan commented Dec 1, 2026

Copy link
Copy Markdown
Member

Thanks @neutrino38, could you please fix the conflicts with master and handle the comment I'v made?

neutrino38 and others added 2 commits December 3, 2026 10:44
Master moved the sources to TypeScript and reworked the test helpers,
which conflicted with this branch.

- src/SIPMessage.d.ts is gone upstream: src/SIPMessage.ts already
  declares IncomingRequest.reply().
- LoopSocket.pair() already exists upstream: take that version.
- The Notifier tests are rewritten on top of the new test helpers
  (startUA, untilDisconnected, TestSocket).
- test-Dialog.ts expected 405 for a SUBSCRIBE with no Contact, and
  terminated its notifier by hand because UA.stop() did not: this
  branch changes both.

Notifier.start() now registers the notifier in the UA only when it has
a dialog. The state check missed a case that master introduced: a
SUBSCRIBE that cannot establish a dialog is answered 400 without
terminating the notifier, which was then registered without a dialog.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Upstream ported Notifier and UA to TypeScript and deleted the .js files
this branch modified. Carry the branch changes over to Notifier.ts and
UA.ts so the pull request applies again: 400 on an invalid SUBSCRIBE,
489 when no newSubscribe listener is set, and notifiers tracked by the
UA so that stop() ends them with a final NOTIFY.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants