-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
http: use listenerCount when adding noop event #46769
http: use listenerCount when adding noop event #46769
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See discussion in #46523 (comment)
I see your point about not being a bug in Node.js. I still think we should prevent the fix anyway. So, can please others gave a final vote on this? Other than that: do you have anything else you want me to change in this PR that I've lost in the discussion in the other issue? |
The fix here actually hides the user error of keeping the socket open. If others think this is a good idea then I will dismiss my request for changes. The events leak warning might be unhelpful but at least it tells the user that there is something wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@nodejs/http Can somebody else upvote or downvote this so we can reach an agreement? |
There is a lot of legacy code out there that emits |
I disagree. Note that there is no crash, only a warning and this silences it. Instead of informing the user that there is something wrong in their code, this just ignores it. In my opinion it is not an improvement, it only promotes invalid usage. Just look at the second test added here. |
The problem is that the user must learn how to fix it. Most of those behaviors are codified in old libraries that are deep in the dependency chain, and it's close to impossible for most users to understand what's going on. My 2 cents is that we must convince them to switch from Node v0.8-era dependencies, as I don't expect those modules to be fixed. If we want to emit a warning for this case, it should be actionable, e.g. "an error event has already been emitted on the request. Please use the destroy method instead". |
Yes that would be perfect. Currently, a bad warning is better than no warning. |
So I leave the "memory leak" prevention and I add an additional warning so the user is beware of the problematic handling. |
Yes, exactly! |
I have no objection with that. Note that there might be other cases where the |
I have a question. The only code needed to make the original warning appear is the following:
Refer to original #43548 for full reproduction steps. Does this mean that in order to make a basic Node.js http server will also require added a |
Are you able to reproduce the issue with that test case?
No, because that is what Node.js does by default if the user does not add a listener for the |
Yes... I am using Jmeter from another machine. I will try it here on some various Node.js versions in a moment.
Ok, then I am confused here. This PR says it is suppsoed to fix #43548 but that issue is pretty basic and doesnt add |
I think the whole discussion originates from #43587 where a test case was added in the form of an invalid |
I am trying to whittle down a simple ideally self-contained example to reproduce the conditions Jmeter is making with the load test. So far I at least seem to have a small example that shows what the const http = require('http')
const server = http.createServer((req, res) => {
res.end(JSON.stringify({ hello: 'world' }))
})
server.listen(3000, '127.0.0.1')
const net = require('net')
server.on('listening', () => {
const socket = net.connect(3000, '127.0.0.1')
socket.on('connect', () => {
socket.write('POST /s HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\n\r\n')
socket.resume()
setTimeout(() => {
socket.end('z')
}, 1000)
})
socket.on('close', () => server.close())
}) |
@dougwilson yes but that example does not cause the "leak" warning, does it? |
No. I am trying to whittle down a simple ideally self-contained example to reproduce the conditions Jmeter is making with the load test. |
77a2064
to
196ec78
Compare
@lpinca I think the issue @dougwilson can eventually be handle as separate issue. Do you still want changes on this or are we good to go? |
Yes, let's wait a little more for @dougwilson's feedback. |
@lpinca No more input received. Shall we wait more or can we land this? |
Wait a few more days, maybe @dougwilson is busy. It is not something that needs an immediate fix and I would prefer not to revert it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Landed in 0d3faae |
PR-URL: #46769 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: #46769 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: #46769 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Fixes #43548.
See discussion in #46523.