-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
finish
event of stream.Writable is not expectedly emitted
#11121
Comments
I'm not sure if this is a bug. You could probably make a case both ways. If we don't end up making a code change as a result of this issue, we should at least update the documentation. |
Another testcase
// async_write.js
const stream = require('stream');
const writable = new stream.Writable();
writable._write = (chunks, encoding, cb) => {
setTimeout(function() {
cb(new Error('write test error'));
}, 0); // _write async, defer callback
};
writable.on('finish', () => {
console.error('finish'); // finish is not emitted
});
writable.on('error', (er) => {
console.error('error');
});
writable.end('test');
// sync_write.js
const stream = require('stream');
const writable = new stream.Writable();
writable._write = (chunks, encoding, cb) => {
cb(new Error('write test error')); // _write sync, callback immediately
};
writable.on('finish', () => {
console.error('finish'); // finish is emitted
});
writable.on('error', (er) => {
console.error('error');
});
writable.end('test'); their behavior is inconsistent, after error occured, |
We should probably be consistent. cc: @nodejs/streams |
@cynron would you like to fire a PR? I think this is an actual bug, good find. @mafintosh what do you think? |
@mcollina I'm sorry I don't know which is expected, always emitted or never emitted? |
@cynron I think it should emit |
In Writable, 'finish' was not emitted when using writev() and cork() in the event of an Error during the write. This commit makes it consistent with the write() path, which emits 'finish'. Fixes: nodejs#11121
Fixed in b153420. |
In Writable, 'finish' was not emitted when using writev() and cork() in the event of an Error during the write. This commit makes it consistent with the write() path, which emits 'finish'. Fixes: #11121 PR-URL: #13195 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Calvin Metcalf <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
In Writable, 'finish' was not emitted when using writev() and cork() in the event of an Error during the write. This commit makes it consistent with the write() path, which emits 'finish'. Fixes: #11121 PR-URL: #13195 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Calvin Metcalf <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Hi,
If _writableState.corked > 0 and
_writev
callback with an error, after callingwritable.end()
,finish
event is not emitted.Test Case:
In
onwriteError
,finishMaybe
should also be checked. a test patch for master works:Please confirm whether it is a bug? make a PR for this?
Thanks!
The text was updated successfully, but these errors were encountered: