Skip to content

Fix double callback call and WNS send bugs - #285

Merged
alex-friedl merged 2 commits into
masterfrom
fix/callback-and-wns-state
Nov 24, 2026
Merged

alex-friedl merged 2 commits into
masterfrom
fix/callback-and-wns-state

Conversation

@alex-friedl

@alex-friedl alex-friedl commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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() or sendWith() 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 wns library calls back with only an error and no response. The code then read response.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 in test/send/sendWNS-accessToken.js, and the concurrency case in test/send/sendWNS.js. All five new tests fail on master and 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

@alex-friedl alex-friedl changed the title Fix double callback invocation and WNS state/accessToken bugs Fix double callback and WNS accessToken/state bugs Nov 24, 2026
@alex-friedl alex-friedl changed the title Fix double callback and WNS accessToken/state bugs Fix double callback call and WNS send bugs Nov 24, 2026
alex-friedl and others added 2 commits November 24, 2026 23:21
- 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
alex-friedl force-pushed the fix/callback-and-wns-state branch from c8a00ba to aa18a83 Compare November 24, 2026 22:21
@alex-friedl alex-friedl self-assigned this Nov 24, 2026
@alex-friedl
alex-friedl merged commit d738652 into master Nov 24, 2026
8 checks passed
@alex-friedl
alex-friedl deleted the fix/callback-and-wns-state branch November 24, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant