Repository navigation
fix: release event sender when fetch rejects - #634
Open
pcbeingused333 wants to merge 2 commits into
Open
pcbeingused333 wants to merge 2 commits into
pcbeingused333 wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
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.jsexercise the fetch fallback by removingXMLHttpRequestand stubbingfetchwith Sinon. They cover rejectedfetchand rejectedresponse.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.src/xhr.js, both cases fail (_sendingstaystrue); with it, both pass (Karma, ChromeHeadless).AI assistance: this change and its validation were prepared with AI coding assistants.