Skip to content
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

stream: improve Writable.destroy performance #35067

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const {
getHighWaterMark,
getDefaultHighWaterMark
} = require('internal/streams/state');
const assert = require('assert');
const {
ERR_INVALID_ARG_TYPE,
ERR_METHOD_NOT_IMPLEMENTED,
Expand Down Expand Up @@ -826,9 +827,16 @@ ObjectDefineProperties(Writable.prototype, {
const destroy = destroyImpl.destroy;
Writable.prototype.destroy = function(err, cb) {
const state = this._writableState;
if (!state.destroyed) {

// Invoke pending callbacks.
if (
state.bufferedIndex < state.buffered.length ||
state[kOnFinished].length
) {
assert(!state.destroyed);
process.nextTick(errorBuffer, state);
}

destroy.call(this, err, cb);
return this;
};
Expand Down