fix(js): remove 1s delay when reading response body#354
Closed
kllnspr3 wants to merge 2 commits intoapify:masterfrom
Closed
fix(js): remove 1s delay when reading response body#354kllnspr3 wants to merge 2 commits intoapify:masterfrom
kllnspr3 wants to merge 2 commits intoapify:masterfrom
Conversation
The abort signal implementation spawned a thread that polled every second, causing all response.text()/json() calls to wait up to 1s even when no abort was triggered. Instead, just check the abort flag on each poll - no thread, no channel, no delay.
The previous implementation only checked the abort flag when poll_next was called, but poll_next isn't re-called while waiting for data from slow servers. This fix adds a tokio interval that periodically wakes the stream (every 1 second) to check the abort flag. When the inner stream is pending: 1. Poll the interval to register its waker 2. When interval fires, check abort flag 3. If aborted, return error immediately 4. Otherwise, continue waiting for next interval tick This ensures abort signals are detected within ~1 second even when the server sends data slowly or hangs.
2f919f2 to
b046b69
Compare
Member
barjin
added a commit
that referenced
this pull request
Jan 12, 2026
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.
Problem
Every call to
response.text()orresponse.json()had a ~1 second delay, even for tiny responses (tested with 121 byte response - still took 1000ms+).The abort signal implementation spawned a polling thread that checked every second for abort state, then merged an abort stream with the data stream. The merged stream waited for both to complete, so even when data finished instantly, it had to wait up to 1s for the polling thread to wake up and exit.
Fix
Check the abort flag directly in
poll_next()instead of using a separate polling thread. No thread, no channel, no merged streams.Before/After