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

socket hangs after close for 45 seconds when invalid namespace #3720

Closed
1 of 2 tasks
coderaiser opened this issue Dec 5, 2020 · 3 comments
Closed
1 of 2 tasks

socket hangs after close for 45 seconds when invalid namespace #3720

coderaiser opened this issue Dec 5, 2020 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@coderaiser
Copy link
Contributor

You want to:

  • report a bug
  • request a feature

Current behaviour

What is actually happening?

Steps to reproduce (if the current behaviour is a bug)

Forked and made reproduceble: fiddle.

Here is code example:
// server
const app = require('express')();
const http = require('http')
const server = http.createServer(app);
const io = require('socket.io')(server);

server.listen(3000, () => {
  console.log('listening on *:3000');
});

io.on('connection', (socket) => {
  console.log('a user connected');
});

// client
const port = 3000;
const {connect} = require('socket.io-client');
const url = `http://localhost:${port}/console`;
const socket = connect(url, {
    reconnection: false,
});

socket.once('connect_error', (e) => {
    console.log('connect_error', e.message);
    socket.close();
    server.close();
});
coderaiser@cloudcmd:~/cloudcmd$ time node example.js
listening on *:3000
connect_error Error: Invalid namespace

real	0m45.342s
user	0m0.360s
sys	0m0.044s

Expected behaviour

What is expected?

Expected that event loop will be freed much faster :).

Setup

  • OS:
  • browser:
  • socket.io version: 3.0.3

Other information (e.g. stacktraces, related issues, suggestions how to fix)

When using getActiveHandlers, see such infomration

Code Example
socket.once('connect_error', (e) => {
    console.log('connect error', e.message);

    server.close(() => {
        socket.close();
        io.close(() => {
            console.log('io closed');
            console.log(process._getActiveHandles());
        });
    });
});
[
<ref *1> WriteStream {
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: null,
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    constructed: true,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: false,
    decoder: null,
    encoding: null,
    readable: false,
    [Symbol(kPaused)]: null
  },
  _events: [Object: null prototype] { end: [Function: onReadableStreamEnd] },
  _eventsCount: 1,
  _maxListeners: undefined,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: false,
    ended: false,
    finished: false,
    destroyed: false,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: true,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    buffered: [],
    bufferedIndex: 0,
    allBuffers: true,
    allNoop: true,
    pendingcb: 0,
    constructed: true,
    prefinished: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    errored: null,
    closed: false,
    closeEmitted: false,
    [Symbol(kOnFinished)]: []
  },
  allowHalfOpen: false,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: null,
  _server: null,
  columns: 203,
  rows: 39,
  _type: 'tty',
  fd: 2,
  _isStdio: true,
  destroySoon: [Function: destroy],
  _destroy: [Function: dummyDestroy],
  [Symbol(async_id_symbol)]: 2,
  [Symbol(kHandle)]: TTY { [Symbol(owner_symbol)]: [Circular *1] },
  [Symbol(kSetNoDelay)]: false,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
},
<ref *2> WriteStream {
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: null,
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    constructed: true,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: false,
    decoder: null,
    encoding: null,
    readable: false,
    [Symbol(kPaused)]: null
  },
  _events: [Object: null prototype] {
    end: [Function: onReadableStreamEnd],
    error: [Function]
  },
  _eventsCount: 2,
  _maxListeners: undefined,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: false,
    ended: false,
    finished: false,
    destroyed: false,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: false,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    buffered: [],
    bufferedIndex: 0,
    allBuffers: true,
    allNoop: true,
    pendingcb: 0,
    constructed: true,
    prefinished: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    errored: null,
    closed: false,
    closeEmitted: false,
    [Symbol(kOnFinished)]: []
  },
  allowHalfOpen: false,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: null,
  _server: null,
  columns: 203,
  rows: 39,
  _type: 'tty',
  fd: 1,
  _isStdio: true,
  destroySoon: [Function: destroy],
  _destroy: [Function: dummyDestroy],
  [Symbol(async_id_symbol)]: 12,
  [Symbol(kHandle)]: TTY { [Symbol(owner_symbol)]: [Circular *2] },
  [Symbol(kSetNoDelay)]: false,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
},
<ref *3> Socket {
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: null,
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: true,
    ended: true,
    endEmitted: true,
    reading: false,
    constructed: true,
    sync: false,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    destroyed: true,
    errored: null,
    closed: true,
    closeEmitted: true,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: false,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: false
  },
  _events: [Object: null prototype] {
    end: [Array],
    close: [Function: socketOnClose],
    error: [Function: socketOnError]
  },
  _eventsCount: 3,
  _maxListeners: undefined,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: true,
    needDrain: false,
    ending: true,
    ended: true,
    finished: true,
    destroyed: true,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: false,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    buffered: [],
    bufferedIndex: 0,
    allBuffers: true,
    allNoop: true,
    pendingcb: 0,
    constructed: true,
    prefinished: true,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: true,
    errored: null,
    closed: true,
    closeEmitted: true,
    [Symbol(kOnFinished)]: []
  },
  allowHalfOpen: true,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: Server {
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    _events: [Object: null prototype],
    _eventsCount: 5,
    _maxListeners: undefined,
    _connections: 0,
    _handle: null,
    _usingWorkers: false,
    _workers: [],
    _unref: false,
    allowHalfOpen: true,
    pauseOnConnect: false,
    httpAllowHalfOpen: false,
    timeout: 0,
    keepAliveTimeout: 5000,
    maxHeadersCount: null,
    headersTimeout: 60000,
    requestTimeout: 0,
    _connectionKey: '6::::3000',
    [Symbol(IncomingMessage)]: [Function: IncomingMessage],
    [Symbol(ServerResponse)]: [Function: ServerResponse],
    [Symbol(kCapture)]: false,
    [Symbol(async_id_symbol)]: 4
  },
  _server: Server {
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    _events: [Object: null prototype],
    _eventsCount: 5,
    _maxListeners: undefined,
    _connections: 0,
    _handle: null,
    _usingWorkers: false,
    _workers: [],
    _unref: false,
    allowHalfOpen: true,
    pauseOnConnect: false,
    httpAllowHalfOpen: false,
    timeout: 0,
    keepAliveTimeout: 5000,
    maxHeadersCount: null,
    headersTimeout: 60000,
    requestTimeout: 0,
    _connectionKey: '6::::3000',
    [Symbol(IncomingMessage)]: [Function: IncomingMessage],
    [Symbol(ServerResponse)]: [Function: ServerResponse],
    [Symbol(kCapture)]: false,
    [Symbol(async_id_symbol)]: 4
  },
  parser: null,
  on: [Function (anonymous)],
  addListener: [Function (anonymous)],
  prependListener: [Function: prependListener],
  setEncoding: [Function: socketSetEncoding],
  _paused: false,
  timeout: 0,
  [Symbol(async_id_symbol)]: 70,
  [Symbol(kHandle)]: null,
  [Symbol(kSetNoDelay)]: true,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kBytesRead)]: 302,
  [Symbol(kBytesWritten)]: 139,
  [Symbol(RequestTimeout)]: undefined,
  [Symbol(websocket)]: WebSocket {
    _events: [Object: null prototype],
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'nodebuffer',
    _closeCode: 1005,
    _closeFrameReceived: true,
    _closeFrameSent: true,
    _closeMessage: '',
    _closeTimer: Timeout {
      _idleTimeout: 30000,
      _idlePrev: [TimersList],
      _idleNext: [TimersList],
      _idleStart: 798,
      _onTimeout: [Function: bound destroy],
      _timerArgs: undefined,
      _repeat: null,
      _destroyed: false,
      [Symbol(refed)]: true,
      [Symbol(kHasPrimitive)]: false,
      [Symbol(asyncId)]: 151,
      [Symbol(triggerId)]: 70
    },
    _extensions: {},
    _protocol: '',
    _readyState: 2,
    _receiver: [Receiver],
    _sender: [Sender],
    _socket: [Circular *3],
    _isServer: true,
    [Symbol(kCapture)]: false
  }
}
]
@darrachequesne
Copy link
Member

I could indeed reproduce the bug, thanks for the detailed explanation 👍

@darrachequesne darrachequesne added the bug Something isn't working label Dec 11, 2020
@coderaiser
Copy link
Contributor Author

Everything works good with socket.io v3.0.5. Thanks a lot :).

coderaiser added a commit to coderaiser/cloudcmd that referenced this issue Jan 5, 2021
@darrachequesne
Copy link
Member

Awesome, thanks for the update!

@darrachequesne darrachequesne added this to the 3.0.5 milestone Jan 5, 2021
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants