http2-wrapper
http2-wrapper copied to clipboard
Adding `timeout` support to Proxy connection
Hello @szmarczak, First of all. I want to say "THANK YOU" - got helped me A LOT and it is fantastic. I really love it. got has a way better timeouts than axios (their timeout handling is broken - PR / Issue), and it has built-in retry support.
Anyway, I've configured H2 over HTTP proxy and just noticed some requests took super long time to fail, or stuck forever.
After some investigation, I noticed that proxy connection can be stuck (or stuck forever) in following cases:
- ClientRequest of
CONNECT
method never emitconnect
event - ClientRequest of
CONNECT
method emittedconnect
event, but session never created or took long time (~20sec)
this might be edge case because:
- Long RTT: Origin server is located in Seoul, South Korea and Proxy Peer is located in US
- Residential Proxy: It is a residential proxy, not a Datacenter Proxy. Some proxy peers has poor network quality.
- Time-limited, stateless environment: Application is running in AWS Lambda
So, It would be nice if we can handle these situations by supporting timeout to proxy connection. There might be another way to setting timeouts (or accessing to connection), If so, please let me know!
Hey @szmarczak, I've successfully implemented two timeouts - timeout for "CONNECT" method and timeout for complete "secureConnect" event of TLS Socket. I'd like to open PR, but just wondering is there any way to implement H2 session acquire timeout? I've been seeing some poor proxy peers that never created any H2 session after emitting secureConnect event. I want to implement timeout to prevent this, but it seems there's no easy way to implement this. I will be appreciated if you could give some advise!
I think you're looking for https://nodejs.org/api/http2.html#http2sessionsettimeoutmsecs-callback
Ah yes, I missed that H2Session.timeout method exists. Thank you for sharing @szmarczak!
Do you think that session acquire timeout is acceptable? Two timeouts (Connect timeout of CONNECT method and Connect timeout of TLS Socket as I earlier mentioned) can be implemented easily without touching original H2 Agent implementation. Extending Http2OverHttp Proxy Agent can implement these two timeouts, but For "H2 Session Acquire Timeout", There's no easy way to implement without touching original H2 Agent code. So just wondering will you accept this kind of timeout implementation.