Skip to content

fix: release event sender when fetch rejects - #634

Open
pcbeingused333 wants to merge 2 commits into
amplitude:v8.xfrom
pcbeingused333:fix/fetch-rejection-c2453
Open

pcbeingused333 wants to merge 2 commits into
amplitude:v8.xfrom
pcbeingused333:fix/fetch-rejection-c2453

Conversation

@pcbeingused333

Copy link
Copy Markdown

A rejected fetch or response body promise leaves the event sender marked as busy, so subsequent uploads return without making a request. This can stop event delivery after a transient network failure in environments using the fetch transport.

Report these transport failures through the existing callback with status 0 and an empty response, matching XMLHttpRequest network errors. This clears the sending flag while keeping queued events available for a later upload. The rejection handler is attached to the response-processing promise so exceptions from the success callback are not handled as a second transport completion.

Testing and validation

Two Mocha regression cases in test/amplitude-client.js exercise the fetch fallback by removing XMLHttpRequest and stubbing fetch with Sinon. They cover rejected fetch and rejected response.text() promises, checking that the sender becomes available again, the original event stays queued, and a retry uploads that same event and empties the queue.

  • Without the change to src/xhr.js, both cases fail (_sending stays true); with it, both pass (Karma, ChromeHeadless).
  • The full Karma suite passes (455 tests); Prettier and ESLint are clean on the touched files.

AI assistance: this change and its validation were prepared with AI coding assistants.

@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 10, 2026 19:29

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant