Repository navigation
XHTTP: bound the dial phase with a deadline - #6584
embogomolov wants to merge 1 commit into
Conversation
Requests are built with context.WithoutCancel so an established stream survives cancellation of the caller's context. The same uncancellable context reaches DialTLSContext, and http2 has no dial timeout of its own, so connection setup runs with no deadline. A server that finishes the TCP handshake and then stalls during TLS parks the dial goroutine in clientConnPool.getClientConn with nothing to wake it. The context is not referenced once a connection is returned, so the deadline cannot affect established streams.
|
这种小超时问题太多了 没有太多实际错误就不接受了 服务端一直不回话是用户配置的服务端的问题 如果是连接整个死掉了会被tcp keepalive探测到 |
|
Keepalive will not catch this.
That makes it a goroutine leak rather than a slow dial. A stalled handshake parks a goroutine in The server side is worth separating out. A plain HTTPS request to the same address and port answers in under a second, so the endpoint is not down. Only the XHTTP handshake stalls. Whatever the server is doing wrong, the client should not leak a goroutine per attempt because of it. A fixed constant is the weakest part of this. |
OpenStreamandPostPacketbuild requests withcontext.WithoutCancelso an established stream survives cancellation of the caller's context. That part is intended.The side effect is that the same uncancellable context reaches
DialTLSContext, andhttp2.Transporthas no dial timeout of its own. Connection setup runs with no deadline at all. A server that completes the TCP handshake and then goes quiet during TLS parks the dial goroutine inclientConnPool.getClientConnwith nothing left to wake it.Give the establishment phase its own deadline.
ctxInneris not referenced once a connection is returned, sodefer cancel()cannot disturb an established stream.The value is a package constant matching the default
policy.Timeouts.Handshake. Reading the policy would need apolicyManager, andcreateHTTPClientcannot reach one: it runs inside theXmuxManagerfactory closure, and its clients are cached inglobalDialerMapand reused, so capturing a request context there would pin the first caller's context to every reuse.For comparison,
grpc/dial.gomarks its nested dial withsession.ContextWithTimeoutOnly, detaching it from the parent while keeping an idle timeout. XHTTP detached it from the parent and from any timeout.