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

net,http2: merge write error handling & property names #19734

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,6 @@ class Http2Stream extends Duplex {

const req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID];
req.callback = cb;

writeGeneric(this, req, data, encoding, cb);

Expand Down Expand Up @@ -1690,7 +1689,6 @@ class Http2Stream extends Duplex {

var req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID];
req.callback = cb;

writevGeneric(this, req, data, cb);

Expand Down
15 changes: 12 additions & 3 deletions lib/internal/stream_base_commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,24 @@ function writevGeneric(self, req, data, cb) {
// Retain chunks
if (err === 0) req._chunks = chunks;

if (err)
return self.destroy(errnoException(err, 'write', req.error), cb);
afterWriteDispatched(self, req, err, cb);
}

function writeGeneric(self, req, data, encoding, cb) {
var err = handleWriteReq(req, data, encoding);

if (err)
afterWriteDispatched(self, req, err, cb);
}

function afterWriteDispatched(self, req, err, cb) {
if (err !== 0)
return self.destroy(errnoException(err, 'write', req.error), cb);

if (!req.async) {
cb();
} else {
req.callback = cb;
}
}

module.exports = {
Expand Down
24 changes: 7 additions & 17 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,23 +758,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
return false;
}

var ret;
var req = createWriteWrap(this._handle, afterWrite);
if (writev)
ret = writevGeneric(this, req, data, cb);
writevGeneric(this, req, data, cb);
else
ret = writeGeneric(this, req, data, encoding, cb);

// Bail out if handle.write* returned an error
if (ret) return ret;

if (!req.async) {
cb();
return;
}

req.cb = cb;
this[kLastWriteQueueSize] = req.bytes;
writeGeneric(this, req, data, encoding, cb);
if (req.async)
this[kLastWriteQueueSize] = req.bytes;
};


Expand Down Expand Up @@ -849,7 +839,7 @@ function afterWrite(status, handle, err) {
if (status < 0) {
var ex = errnoException(status, 'write', this.error);
debug('write failure', ex);
self.destroy(ex, this.cb);
self.destroy(ex, this.callback);
return;
}

Expand All @@ -858,8 +848,8 @@ function afterWrite(status, handle, err) {
if (self !== process.stderr && self !== process.stdout)
debug('afterWrite call cb');

if (this.cb)
this.cb.call(undefined);
if (this.callback)
this.callback.call(undefined);
}


Expand Down