Repository navigation
Fix double callback call and WNS send bugs - #285
Merged
Merged
Conversation
- send()/sendWith(): use a two-argument then() so an exception thrown by the user callback no longer re-invokes the callback with that error - sendWNS: keep results per call instead of in module-level state, so concurrent calls no longer mix or swap results - sendWNS (accessToken mode): handle wns calling back with only an error (request errors and non-2xx statuses such as an expired channel), which threw inside the HTTP callback and left the send promise unsettled; take a refreshed token from the error and keep the current one otherwise Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alex-friedl
force-pushed
the
fix/callback-and-wns-state
branch
from
November 24, 2026 22:21
c8a00ba to
aa18a83
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three bugs that came up while reviewing #282. All of them are already on
master, so this can ship as a 6.0.x patch.The callback runs twice when it throws
If the callback passed to
send()orsendWith()threw an error, the.catch()that followed called it again with that error. The returned promise also rejected, even though the push itself had worked.The callback now runs exactly once. If it throws, the promise rejects with its error.
WNS sends with an access token could hang
When a WNS push fails, for example because the channel has expired, the
wnslibrary calls back with only an error and no response. The code then readresponse.newAccessToken, which threw inside the HTTP callback, and the send promise never resolved or rejected.It now takes the refreshed token from the error when there's no response. A related fix: when WNS didn't issue a new token, the next request used to go out without any token. It now keeps the current one.
Concurrent WNS sends mixed up their results
Results were collected in a single module-level variable, so two sends running at the same time wrote into each other's results and could return the wrong set. Each call now keeps its own.
Testing
Each fix comes with tests in the existing file for its module: the callback cases in
test/push-notifications/basic.js, the token cases intest/send/sendWNS-accessToken.js, and the concurrency case intest/send/sendWNS.js. All five new tests fail onmasterand pass here. The WNS tests simulate failures the way the real library reports them.The full suite passes (101 tests), along with lint and build. CI is green on Node 20, 22, 24 and 26.
🤖 Generated with Claude Code