Skip to content

Error [ERR_INTERNAL_ASSERTION] #48358

@mStirner

Description

@mStirner

Version

v16.20.0

Platform

Linux stirner 5.4.0-149-generic #166~18.04.1-Ubuntu SMP Fri Apr 21 16:42:44 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Run the following code:

client.js

const { Agent } = require("http")
const { createConnection } = require("net");
const WebSocket = require("ws");

const agent = new Agent({
    maxSockets: 1,
    keepAlive: true
});


agent.createConnection = (...args) => {

    console.log("Create connection", args);

    let socket = createConnection(...args);


    return new Proxy(socket, {

    });

};



const ws1 = new WebSocket("ws://127.0.0.1:8080", {
    agent
});

const ws2 = new WebSocket("ws://127.0.0.1:8080", {
    agent
});


[ws1, ws2].forEach((ws) => {

    ws.on("open", () => {
        console.log("WebSocket opend: %s", ws.url);
    });

    ws.on("close", () => {
        console.log("WebSocket closed: %s", ws.url);
    });

});

server.js

const { Server } = require("ws");

const wss = new Server({
    port: 8080
});


wss.on("connection", (ws) => {

    console.log("Client connected");

    ws.on("close", () => {
        console.log("Client disconnected");
    });

});

wss.on("listening", () => {
    console.log("Server listening")
});

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

Every time node client.js is executed.
The root of this issue is the proxy inside of agent.createConnection.

I try to understand the anatomy/life cycle of a http request better.
Especially the role and handling of the agent.

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

The proxied socket object returned from agent.createConnection, should trigger the defined traps. (Dosnt matter if there are any or not).
As soon as agent.createConnection, return the proxy object, the error is thrown.

What do you see instead?

node:internal/assert:14
    throw new ERR_INTERNAL_ASSERTION(message);
    ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:387:5)
    at assert (node:internal/assert:14:11)
    at Socket.socketOnData (node:_http_client:532:3)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Additional information

Complete command output:

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Create connection [
  [Object: null prototype] {
    protocolVersion: 13,
    maxPayload: 104857600,
    perMessageDeflate: true,
    followRedirects: false,
    maxRedirects: 10,
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: true,
      maxSockets: 1,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 0,
      createConnection: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    createConnection: [Function: netConnect],
    socketPath: undefined,
    hostname: undefined,
    protocol: undefined,
    timeout: undefined,
    method: undefined,
    host: '127.0.0.1',
    path: null,
    port: '8080',
    defaultPort: 80,
    headers: {
      'Sec-WebSocket-Version': 13,
      'Sec-WebSocket-Key': 'nVSV53R5OFgshY881raCAw==',
      Connection: 'Upgrade',
      Upgrade: 'websocket',
      'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits'
    },
    maxSockets: 1,
    keepAlive: true,
    servername: '',
    _agentKey: '127.0.0.1:8080:',
    encoding: null,
    keepAliveInitialDelay: 1000
  },
  [Function (anonymous)]
]
node:internal/assert:14
    throw new ERR_INTERNAL_ASSERTION(message);
    ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:387:5)
    at assert (node:internal/assert:14:11)
    at Socket.socketOnData (node:_http_client:532:3)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions