Skip to content

TCP socket won't call end() callback if wasn't connected #47322

Closed
@Antonius-S

Description

Version

v18.15.0

Platform

Win 8.1 x64

Subsystem

net

What steps will reproduce the bug?

'use strict';

const net = require('net');
const stream = require('stream');

function check(stm)
{
  stm.on('finish', () => console.log('finish'));
  stm.on('close', () => console.log('close'));
  stm.end(() => console.log('ended'));
}

// nothing is printed
check(new net.Socket());
// 'finish' and 'ended' is printed
// check(new stream.Writable());

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

Expect at least 'ended' to show

What do you see instead?

nothing printed

Additional information

All streams seem to always call the callback from end() but non-connected sockets do not thus violating stream.Writable API.

Why it is needed: I use universal function to close stream gracefully and when it's done call destroy. With this behavior the function stucks at non-connected sockets. Currently I seem to have to check stream.writable and only call end when it's true.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions