Skip to content

Closing zlib stream may throw uncaught exceptionΒ #15625

Closed
@nakedible-p

Description

@nakedible-p

When calling .close() on a zlib.createGunzip() stream while the engine is still working on decompressing some stuff, sometimes this exception is thrown:

zlib.js:633
      var newReq = self._handle.write(flushFlag,
                               ^

TypeError: Cannot read property 'write' of null
    at Zlib.callback (zlib.js:633:32)

Looking at the code, it seems that when _processChunk sets a callback, it does not sufficiently check that this._handle has not been unset in the meantime. The earlier code has assert(this._handle, 'zlib binding closed'); check, but the callback code does not.

But even the assert is wrong, as calling .close() on a stream, even when there's unprocessed data, should not throw any exceptions. I guess the function should check for this._closed similarily as it checks for this._hadError currently.

Unfortunately this bug is triggered very rarely on a production system, so I haven't been able to write short code to reproduce the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.streamIssues and PRs related to the stream subsystem.zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions