Sitelet https://github.com/nodejs/node/issues/30841
Skip to content

net: write(cb) not called if destroy():ed before 'connect' #30841

Description

@ronag

See #30839

_writeGeneric waits for 'connect'

node/lib/net.js

Line 759 in cf5ce2c

this.once('connect', function connect() {
which might never be emitted due to

node/lib/net.js

Lines 1106 to 1108 in cf5ce2c

if (self.destroyed) {
return;
}

I believe this will fail:

const socket = createSocketBeforeConnect();
socket.write('asd', common.mustCall());
socket.destroy();

Activity

  1. changed the title [-]net: write(cb) not called if destroyed[/-] [+]net: `write(cb)` not called if `destroy()`:ed before 'connect'[/+] on Dec 7, 2019
  2. changed the title [-]net: `write(cb)` not called if `destroy()`:ed before 'connect'[/-] [+]net: `write(cb)` not called if `destroy()`:ed before `'connect'`[/+] on Dec 7, 2019
  3. added
    netIssues and PRs related to the net subsystem.
    on Dec 7, 2019
  4. ronag commented on Jan 3, 2020

    @ronag
    MemberAuthor

    This is fixed

  5. lpinca commented on Jan 5, 2020

    @lpinca
    Member

    If the expectation is that callback is called this is not fixed.

    const assert = require('assert');
    const net = require('net');
    
    const socket = new net.Socket();
    
    socket.connect({
      port: 80,
      host: 'example.com',
      lookup() {}
    });
    
    assert(socket.connecting);
    
    let called = false;
    
    socket.write('foo', function() {
      called = true;
    });
    
    socket.destroy();
    
    process.on('exit', function() {
      assert(called);
    });
  6. reopened this on Jan 5, 2020
  7. ronag commented on Jan 5, 2020

    @ronag
    MemberAuthor

    Yea, we should add a test for that.

    This seems related to the whole constructing state which in this case never gets resolved, i.e. _write never finishes https://github.com/nodejs/node/blob/master/lib/net.js#L763. I can dig into this once/if #29656 lands.

  8. lpinca commented on Jan 5, 2020

    @lpinca
    Member

    yes, _writeGeneric() is never called as 'connect' is never emitted.

  9. ronag commented on Jan 6, 2020

    @ronag
    MemberAuthor

    pending resolution to discussion in #31179

  10. ronag commented on Apr 19, 2020

    @ronag
    MemberAuthor
    'use strict';
    
    const common = require('../common');
    const assert = require('assert');
    const net = require('net');
    
    const socket = new net.Socket();
    
    socket.connect({
      port: 80,
      host: 'example.com',
      lookup() {}
    });
    
    assert(socket.connecting);
    
    socket.write('foo', common.mustCall());
    socket.destroy();
  11. ronag commented on Apr 19, 2020

    @ronag
    MemberAuthor

    This requires #29656 in order to be fully resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.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