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: check for close on stream, not parent #25026

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
4 changes: 2 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ Socket.prototype._final = function(cb) {
};


function afterShutdown(status, handle) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why this gets called with the wrong handle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from here: https://github.com/nodejs/node/blob/v11.4.0/src/stream_base.cc#L383
This in turn is set by https://github.com/nodejs/node/blob/v11.4.0/src/stream_base-inl.h#L86
which is called by https://github.com/nodejs/node/blob/v11.4.0/src/tls_wrap.cc#L73

TLSWrap's stream is the external stream from here: https://github.com/nodejs/node/blob/v11.4.0/lib/_tls_wrap.js#L423

which is the unencrypted socket passed into the constructor: https://github.com/nodejs/node/blob/v11.4.0/lib/_tls_wrap.js#311

In summary, it gets the underlying socket's stream rather than the encrypted stream (TLSSocket). Node stream operations appear to be performed on TLSSocket only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation.

var self = handle[owner_symbol];
function afterShutdown(status) {
var self = this.handle[owner_symbol];

debug('afterShutdown destroyed=%j', self.destroyed,
self._readableState);
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-tls-close-event-after-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
const common = require('../common');

if (!common.hasCrypto)
common.skip('missing crypto');

// Issue #24984
// 'close' event isn't emitted on a TLS connection if it's been written to
// (but 'end' and 'finish' events are). Without a fix, this test won't exit.

const tls = require('tls');
const fixtures = require('../common/fixtures');
let cconn = null;
let sconn = null;

function test() {
if (cconn && sconn) {
cconn.resume();
sconn.resume();
sconn.end(Buffer.alloc(1024 * 1024));
cconn.end();
}
}

const server = tls.createServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
}, function(c) {
c.on('close', function() {
server.close();
});
sconn = c;
test();
}).listen(0, common.mustCall(function() {
tls.connect(this.address().port, {
rejectUnauthorized: false
}, common.mustCall(function() {
cconn = this;
test();
}));
}));