fix: upload stalls with deferred length when size is multiple of chunkSize - #866
Open
Yanhu007 wants to merge 1 commit into
Open
fix: upload stalls with deferred length when size is multiple of chunkSize#866Yanhu007 wants to merge 1 commit into
Yanhu007 wants to merge 1 commit into
Conversation
…kSize When using uploadLengthDeferred with a Node.js stream whose total size is exactly divisible by chunkSize, readChunk() hangs forever. After the last aligned chunk is consumed, readChunk is called again but the stream has no more data. It only listens for 'readable' events, but the stream emits 'end' instead. Since there is no 'end' listener, the returned promise never resolves and the upload stalls silently. Fix: - Listen for 'end' in readChunk and resolve with an empty buffer - Add a readableEnded guard at the top for already-ended streams - Clean up all listeners on resolution to prevent leaks Fixes tus#779
Member
|
Thank you for this report and providing a fix as well. Could you add a unit test covering this case so we'll catch any future regression? |
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 #779
Problem
When using
uploadLengthDeferred: truewith a Node.js stream whose total size is exactly divisible bychunkSize, the upload hangs forever after the last chunk.Root cause: After consuming the last aligned chunk,
readChunk()is called again. The stream has no more data and emitsend, butreadChunkonly listens forreadableevents — the promise never resolves.Timeline
slice(0, 7)→ reads 7 bytes,done: falseslice(7, 14)→ reads 7 bytes, stream buffer depleted,done: falseslice(14, 21)→ buffer empty,readChunk()called → hangs (stream emitsend, notreadable)Fix
endevent listener inreadChunk()that resolves with an empty bufferreadableEndedguard at entry for already-ended streamserror,readable,end) on resolution