Repository navigation
Error [ERR_INTERNAL_ASSERTION] #48358
Description
Activity
Please post a test case that does not use third-party dependencies like ws. As the error message says, it's likely incorrect usage of node.js internals.
I'll reopen this when you've updated the test case.
Please post a test case that does not use third-party dependencies like ws. As the error message says, it's likely incorrect usage of node.js internals.
Sure, no problem.
The issue is still present with the native http module/request:const { Agent, request } = require("http") const { createConnection } = require("net"); const agent = new Agent({ maxSockets: 1, keepAlive: true }); agent.createConnection = (options) => { let { host, port } = options; console.log("Create connection", host, port); let socket = createConnection(options); return new Proxy(socket, { // proxy handler here }); }; let req = request("http://example.com", { agent }); req.on("response", (res) => { res.pipe(process.stdout); }); req.end();
Output:
Create connection example.com 80 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' }As said above, without the proxied socket, everything works fine.
It's not surprising it doesn't work because the proxy breaks object equivalence:
const o = {} const p = new Proxy(o, {}) assert(o === p) // falseThat becomes relevant when
this !== socketin callbacks.I don't consider that a bug because you're breaking a rather fundamental assumption. Node is right to complain about "incorrect usage of Node.js internals." :-)
Hmm, thats not good for me 😞
I try to better understand the anatomy of a http request and the job of the agent in this context.
For that i wanted to know when/which property/method of the underlying net socket is accessed/called.Is there somewhere a diagram of the workflow of the agent?
Like here for streams?The documentation for
agent.createConnection()lays out the contract: in a nutshell it needs to adhere to thestream.Duplexprotocol.
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
server.js
How often does it reproduce? Is there a required condition?
Every time
node client.jsis 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?
Additional information
Complete command output: