Pumpify behaves differently in Node 8 and Node 10

Viewed 123

For some reason when an error is emitted on stream in node 8 this is propagated correctly and followed by end event, however on node 10, this happens in reverse order. (using latest 2.0.1 version of pumpify)

Example:

'use strict';

const { PassThrough, Writable } = require('stream');

const pumpify = require('pumpify');

const stream1 = new PassThrough();
const stream2 = new Writable();

const combined = pumpify(stream1, stream2);

combined.on('end', () => {
    console.log('Stream end');
});
combined.on('error', e => {
    console.log('Stream error: ', e);
});

stream1.emit('error', 'aaa');
nvm use 8
Now using node v8.17.0 (npm v6.13.4)

node tmp.js
Stream error:  aaa
Stream end
nvm use 10
Now using node v10.19.0 (npm v6.13.4)

node tmp.js
Stream end
Stream error:  aaa

Notice the reverse order of events.

Is this expected behaviour? Am I doing something wrong?

1 Answers

Still not entirely sure what is going on, just in case it helps someone. The issue seems to be with PassThrough being empty. If I replace it with tar-fs and add entry on top of the stream it seems to be working as expected

'use strict';

const { Writable } = require('stream');

const { pack } = require('tar-fs');
const pumpify = require('pumpify');

const stream1 = pack();
const stream2 = new Writable();

const combined = pumpify(stream1, stream2);

combined.on('end', () => {
    console.log('Stream end');
});
combined.on('error', e => {
    console.log('Stream error: ', e);
});

stream1.entry({ name: 'file1' }, 'artbitrary file1 contents');
stream1.emit('error', 'aaa');
nvm use 8
Now using node v8.17.0 (npm v6.13.4)

node tmp.js
Stream error:  aaa
Stream end
nvm use 10
Now using node v10.19.0 (npm v6.13.4)

node tmp.js
Stream error:  aaa
Stream end
Related