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

test: fix tls-inception #4195

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 6 additions & 12 deletions test/parallel/test-tls-inception.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ var fs = require('fs');
var path = require('path');
var net = require('net');

var options, a, b, portA, portB;
var gotHello = false;
var options, a, b;

var body = new Buffer(4000).fill('A');
var body = new Buffer(400000).fill('A');
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bit over the top, probably? What do you think about a compromise with a 40000?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've used that value to reproduce the ECONNRESET error in OS X consistently.


options = {
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
Expand All @@ -33,7 +32,7 @@ a = tls.createServer(options, function(socket) {
dest.pipe(socket);
socket.pipe(dest);

dest.on('close', function() {
dest.on('end', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Reason?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried to explain it the best I can (from my understanding) in the commit log: santigimeno@432a86e

When sending a very large buffer (400000 bytes) the test fails due to
the client socket from the `a` server erroring with `ECONNRESET`.
There's a race condition between the closing of this socket and the `ssl`
socket closing on the other side of the connection. To improve things,
destroy the socket as soon as possible: in the `end` event of the `dest`
socket.

Running the test with dtruss I could see the ssl closing and the socket sending data afterwards. This data was from the SSL_shutdown called when the dest socket was closed (I guess because both sockets were piped)
What I don't really understand is how ssl receives an EOF, thus emitting the end event, before the other end has sent the shutdown. (I'm not sure if it makes sense).

Copy link
Member

Choose a reason for hiding this comment

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

There are two ways to EOF for TLS connection: TCP FIN packet, and TLS close_notify alert (i.o.w. shutdown).

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Thanks for the explanation!

socket.destroy();
});
});
Expand All @@ -43,10 +42,6 @@ b = tls.createServer(options, function(socket) {
socket.end(body);
});

process.on('exit', function() {
assert(gotHello);
});

a.listen(common.PORT, function() {
b.listen(common.PORT + 1, function() {
options = {
Expand All @@ -62,15 +57,14 @@ a.listen(common.PORT, function() {
});
ssl.setEncoding('utf8');
var buf = '';
ssl.once('data', function(data) {
ssl.on('data', function(data) {
buf += data;
gotHello = true;
});
ssl.on('end', function() {
ssl.on('end', common.mustCall(function() {
assert.equal(buf, body);
ssl.end();
a.close();
b.close();
});
}));
});
});