Repository navigation
fix(cli): close asset streams when clients disconnect - #5321
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
serveFileWithRange pipes a ReadStream into the response, and when the client disconnects pipe unpipes but leaves the paused stream and its fd open; destroying the stream on the response's close fixes that for full, ranged and cached-proxy responses, which all funnel through this helper. Main still lacks the listener. On a normal completion close fires after finish, when the stream has already ended, so the destroy is a no-op and cannot truncate output, including on the in-process socket-pair path. The test spies createReadStream, disconnects after the first chunk, and polls until the stream is closed and destroyed for all four request shapes, then checks the server still answers. Need: yes · Size: ok · Reuse: n/a · Simpler: one line, already minimal.
— Rames
Cancelling a large download from the CLI's local project server unpipes the response but leaves its paused ReadStream and file handle open. Destroy the stream when the response closes, covering cancelled and completed requests through the same file-serving helper. Native and cached proxy assets both use this path.
The current-main integration preserves its new in-process server behavior and tests.
Validation: