Skip to content

'close' listener stop working with socket.removeAllListeners('end')Β #24577

@acappella2017

Description

@acappella2017
  • Version:v10.13.0
  • Platform:Darwin Kernel Version 18.2.0
  • Subsystem:TLSSocket

Run below snippet on Node 10, the close listener will never be trigged.
If we comment out the line socket.removeAllListeners('end');, The close listener is trigged as expected.

But on Nodejs 8, close listener works with or without the removeAllListeners call.

const tls = require('tls');

const options = {
  host : "www.baidu.com",
  port: 443,
};

const socket = tls.connect(options, () => {
  console.log('===client connected');
  socket.end();
});

socket.removeAllListeners('end');

socket.on('end', () => {
  console.log('===client ends');
});

socket.on('close', ()=> {
  console.log('===client close' );
});

Output in Nodejs 10:

===client connected
===client ends

Output in Nodejs 8:

===client connected
===client ends
===client close

I believe this issue is the root cause of ldapjs/node-ldapjs#483

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions