Copilot commented on code in PR #3852:
URL: https://github.com/apache/avro/pull/3852#discussion_r3567570048
##########
lang/js/lib/files.js:
##########
@@ -247,11 +315,21 @@ BlockDecoder.prototype._createBlockCallback = function ()
{
this._pending++;
return function (err, data) {
+ // Always account for this block's completion, even on error, so a failed
+ // decompression (e.g. the size safeguard firing) cannot leave `_pending`
+ // permanently above zero and hang the stream at finish.
+ self._pending--;
if (err) {
self.emit('error', err);
+ // If the writable side already finished and this was the last pending
+ // block, end the readable side too so a consumer waiting on the queue is
+ // not left hanging after the error.
+ if (self._needPush && self._finished && !self._pending) {
+ self._needPush = false;
+ self.push(null);
+ }
return;
}
Review Comment:
On decompression/size errors, the decoder only emits an 'error' event but
does not destroy itself. When used via `createFileDecoder`
(ReadStream.pipe(BlockDecoder)), the upstream file stream will typically
continue reading and feeding data after the error, potentially doing
unnecessary I/O/CPU work (and possibly emitting multiple errors) after the
first oversized/malformed block is detected. Destroying the decoder on first
decompression error will promptly tear down the pipe and stop further
processing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]