Skip to content

'end' event not called on connected socket wrapped with tls #10871

@zivbr

Description

@zivbr
  • Version: v6.9.4, v7.4.0
  • Platform: Linux pc 4.2.0-30-generic docs: re-word project messaging #36-Ubuntu SMP Fri Feb 26 00:58:07 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: net, tls

When wrapping an existing socket with tls, the socket's 'end' event is not called if the socket was already connected.

Example:

In this case 'end' will be called:

var Socket = require('net').Socket;
var tls = require('tls');

var HOST = 'www.google.com';

var socket = new Socket();
var tlsOptions = {
  host: HOST,
  socket: socket
};

socket.on('close', function() { console.log('close'); });
socket.on('end', function() { console.log('end'); });

var tlsSocket = tls.connect(tlsOptions, function() {
  console.log('connected');
  tlsSocket.end();
});

socket.connect({
  port: 443,
  host: HOST
});

In this case 'end' will not be called:

var Socket = require('net').Socket;
var tls = require('tls');

var HOST = 'www.google.com';

var socket = new Socket();
var tlsOptions = {
  host: HOST,
  socket: socket
};

socket.on('close', function() { console.log('close'); });
socket.on('end', function() { console.log('end'); });

socket.connect({
  port: 443,
  host: HOST
});

var tlsSocket = tls.connect(tlsOptions, function() {
  console.log('connected');
  tlsSocket.end();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions