Skip to content

zlib streams emitting data after end #2485

Closed
@jhamhader

Description

@jhamhader

Hey,

I noticed that zlib streams still emit data (i.e in deflate stream, it writes the adler32 checksum) after .end() has been called.
Here is a test (with useful prints, obviously should be removed later) which fails on the recent 3.0.x:
(notice the data written after "deflate end cb")

var zlib = require('zlib');

var input = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.'
var deflate = zlib.createDeflate();
var alreadyEnded = 0;

deflate.on('data', function(chunk) {
        console.log('deflate data:');
        console.log(chunk);
        if (alreadyEnded) {
                throw "Stream already ended"
        }   
});

deflate.on('prefinish', function() {
        console.log('deflate prefinish event');
});

deflate.on('finish', function() {
        console.log('deflate finish event');
});

deflate.write(input);
defalte.flush(function() {
        deflate.end(function () {
                console.log('deflate end cb');
                alreadyEnded = 1;
        });
});

I would really like to help fix this issue and it to be my first contribution here, so if anyone is willing to help with mentoring, that will be great.
From what I understand, calling end() triggers calling endWritable() which calls prefinish().
Transform's _flush() is registered to the prefinish event. Problem is, _flush() calls an async zlib Write(). Meanwhile, endWritable continues and calls end()'s callback.

Am I on to an issue?
Should zlib's _flush write synchronously if this is the last write?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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