| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
On the other hand sockets that have not been used in a while might unnecessarily timeout. I think LIFO is fine but we do need to remove sockets from the free list when they timeout (which we currently don't). I'm unsure whether LIFO or FIFO is better here... Also, this might be a good idea to apply when the free list is full, i.e. instead of throwing away the most recent socket (as we currently do), we should throw away the least recently used. |
Sorry, something went wrong.
|
Why would we want to remove then until we actually try them? That's the current behavior. You have a good idea on the second part about what should be thrown away, updated commit pending. |
Sorry, something went wrong.
Because they have timed out. I don't think that's the current behavior? |
Sorry, something went wrong.
|
Are there event handlers still reading from the socket once they are placed in the agent pool? I don't believe so. If there aren't any handlers waiting to read how will the code know the socket has timed out? |
Sorry, something went wrong.
By adding a handler. See, #23752. |
Sorry, something went wrong.
| this.maxFreeSockets > 0 && | ||
| count <= this.maxSockets) { | ||
| if (freeLen >= this.maxFreeSockets) { | ||
| const oldest = this.freeSockets[name].shift(); |
There was a problem hiding this comment.
nit, freeSockets.shift()
Sorry, something went wrong.
| if (freeLen >= this.maxFreeSockets) { | ||
| const oldest = this.freeSockets[name].shift(); | ||
| oldest.destroy(); | ||
| } else { |
There was a problem hiding this comment.
nit, else if (!freeSockets)
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not quite following, could you explain a bit more.
Sorry, something went wrong.
There was a problem hiding this comment.
the block inside of the else is for the case when !freeSockets, could be simplified
Sorry, something went wrong.
There was a problem hiding this comment.
it's a nit, no biggie
Sorry, something went wrong.
|
Would be nice if you could make a test for this. |
Sorry, something went wrong.
|
Defensively marking this semver-major for now. It's possible this wouldn't break anyone but we need to verify. |
Sorry, something went wrong.
|
Ping @nodejs/http |
Sorry, something went wrong.
|
A benchmark would be good. We might already have a relevant benchmark. I'm not sure.
At least in theory, isn't this an implementation detail the user need not worry about? (But I wouldn't oppose a test either. Just not sure if it's necessary.) |
Sorry, something went wrong.
Agreed. Nice to have. |
Sorry, something went wrong.
Sockets are added to the free list with .push() but they were being removed with .shift(). This meant the sockets where being removed in FIFO order, but this changes it to LIFO. Since older sockets may be closed based due to inactivity on the server it is more likely that a socket that is recently used will be able to successfully process the next request. Rather than destroying the last used socket destroy the oldest socket in the free list in push() on the last recently used socket.
Sorry, something went wrong.
Although there's some ambiguity around the author ready label, I would say this is not yet author ready because it is semver-major and therefore requires two approvals from the TSC. /ping @nodejs/tsc Please review! (@jasnell described marking this as semver-major as being done "defensively" so it might not be semver-major after all. Opinions one way or the other are welcome.) |
Sorry, something went wrong.
There was a problem hiding this comment.
I would like to have a test for this behavior.
Sorry, something went wrong.
|
Very good work. This is one of the main changes I did in https://github.com/mcollina/undici to improve the handling of keep-alive connections. |
Sorry, something went wrong.
|
There is a related issue to this that we might want to consider before landing this. We have a problem with sockets in the freelist that timeout are not removed from the list. This change might make that worse, since the least recently used socket is less likely to be used and thus timeout, then when it is actually used the request using it would fail. |
Sorry, something went wrong.
|
@ronag Does this mean that the request isn't retried on another connection automatically or is the request simply failed with a connection reset error? |
Sorry, something went wrong.
|
@ronag is there a test case that stresses this condition? |
Sorry, something went wrong.
If the user doesn't abort the request in a 'timeout' event handler (this is optional at the moment), the socket might be incorrectly re-used and the corresponding request would potentially fail, probably with ECONNRESET.
Nope, would be nice to have a tests for it. |
Sorry, something went wrong.
|
Just to clarify, I believe my concern is already a problem, however this PR might make it worse. |
Sorry, something went wrong.
|
@rustyconover: I openend a separate PR to address my concern. I think this PR is good as is once a test is added, though I would prefer to wait for #32000 to land before landing this. |
Sorry, something went wrong.
|
@ronag I just wrote a test for the LIFO behavior of this PR. Let me know what you think. |
Sorry, something went wrong.
@mcollina I just added a test. |
Sorry, something went wrong.
Add a test that ensures the HTTP agent reuses sockets in a LIFO fashion rather than FIFO.
|
@mcollina I believe I've addressed your suggestions in the updated commits. Please let me know what you think. Thank you! 🙏 |
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
|
Great! 👍 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Sockets are added to the free list with .push() but they were
being removed with .shift(). This meant the sockets where being
removed in FIFO order, but this changes it to LIFO. Since older
sockets may be closed based due to inactivity on the server it is
more likely that a socket that is recently used will be able to
successfully process the next request.