Q about agent and keepAliveMaxTimeout #3329
-
Hi, I have a couple of questions to ask. Thanks for your help. Context:
1st question: When I use a per-request agent, do I have to explicitly close it? 2nd question: Regarding keepAliveMaxTimeout, is the check done before getting a connection from the pool (which could happen after keepAliveMaxTimeout seconds if there is no activity)? Or is there a timer or something that will wake up after an inactivity period of keepAliveMaxTimeout seconds, and close the connection? So if there is a timer and I understand correctly, after keepAliveMaxTimeout and without activity, no more TCP connection should be left open in the pool... Thanks a lot for your work!
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Likely so
The check is done inside the client to verify if the connection must be reset. You'd get best performance by having a short keep alive and reusing the agent |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick reply! Hmm, your 2nd answer bores me. As you know, we cannot be notified when the runtime execution (or sandbox) of the AWS lambda function is stopped by AWS. But we know (from experience) that the sandbox will remain alive for at least 10 minutes (maybe much more, but after 10 minutes of inactivity, it is risky to consider it alive). So I thought setting keepAliveMaxTimeout to 10 minutes would be ok. But this is not the case, because the check is performed when the client requests a connection to the pool. I guess I need to implement some sort of timer at my lambda function level, and close all the connections from the pool after 10 minutes of inactivity from the lambda function point of view. How can I close all TCP connections from the undici pool, while still keeping the pool functional if a new connection arrives? Thanks again. |
Beta Was this translation helpful? Give feedback.
-
If the client connection is renewed when requested from the pool, AWS will destroy the Lambda sandbox with all open connections in the pool. Which is not optimal from the server's point of view (resource leak). |
Beta Was this translation helpful? Give feedback.
Likely so
The check is done inside the client to verify if the connection must be reset.
You'd get best performance by having a short keep alive and reusing the agent