Repository navigation
Notifier: 489/400 to incoming SUBSCRIBE, final NOTIFY on UA.stop() - #980
neutrino38 wants to merge 4 commits into
Conversation
- 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>
|
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>
|
It's done |
| this.receiveRequest(this._initial_subscribe); | ||
|
|
||
| // A fetch (Expires: 0) is already over. | ||
| if (this._state !== C.STATE_TERMINATED) { |
There was a problem hiding this comment.
This condition always matches. Few lines above (221) stated.
There was a problem hiding this comment.
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.
|
Thanks @neutrino38, could you please fix the conflicts with master and handle the comment I'v made? |
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>
Why
newSubscribelistener, an incoming SUBSCRIBE gets 405 Method Not Allowed, even though SUBSCRIBE appears in theAllowheader ofthat same response. What is unsupported is the event package, which is what 489 Bad Event says (RFC 6665 4.2.1.1).
UA.stop()leaves the subscriptions we serve open. Subscribers learn we are gone only when their subscription expires.IncomingRequest.reply()is not declared, although everynewSubscribelistener 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 activeNotifier, before the UA is closed. The UA tracksnotifiers through
newNotifier()anddestroyNotifier(), as it does for sessions. A fetch SUBSCRIBE (Expires: 0) is not tracked, since it isalready over. The final NOTIFY carries no
reason, so subscribers may re-subscribe whenever they want (RFC 6665 4.1.3).SIPMessage.d.tsnow declaresIncomingRequest.reply().Behaviour changes
The response code becomes 489 or 400 where it used to be 405. Applications that already call
notifier.terminate()beforeua.stop()areunaffected, because
terminate()is idempotent.Tests
src/test/test-Notifier.tscovers three cases: 489 without a listener, 400 on a SUBSCRIBE with no Event header, and the final NOTIFY onUA.stop(). All three fail without this change.npm testandnpm run lintpass.