Make DeadlineConn http.Listener compatible (#20635)

HTTP likes to slap an infinite read deadline on a connection and 
do a blocking read while the response is being written.

This effectively means that a reading deadline becomes the 
request-response deadline.

Instead of enforcing our timeout, we pass it through and keep 
"infinite deadline" is sticky on connections.

However, we still "record" when reads are aborted, so we never overwrite that.

The HTTP server should have `ReadTimeout` and `IdleTimeout` set for the deadline to be effective.

Use --idle-timeout for incoming connections.
This commit is contained in:
Klaus Post
2024-11-12 12:41:41 -08:00
committed by GitHub
parent 55f5c18fd9
commit b5177993b3
5 changed files with 42 additions and 38 deletions

View File

@@ -421,6 +421,7 @@ func serverHandleCmdArgs(ctxt serverCtxt) {
Interface: ctxt.Interface,
SendBufSize: ctxt.SendBufSize,
RecvBufSize: ctxt.RecvBufSize,
IdleTimeout: ctxt.IdleTimeout,
}
// allow transport to be HTTP/1.1 for proxying.
@@ -878,6 +879,8 @@ func serverMain(ctx *cli.Context) {
UseHandler(setCriticalErrorHandler(corsHandler(handler))).
UseTLSConfig(newTLSConfig(getCert)).
UseIdleTimeout(globalServerCtxt.IdleTimeout).
UseReadTimeout(24 * time.Hour). // (overridden by listener.config.IdleTimeout on requests)
UseWriteTimeout(24 * time.Hour). // (overridden by listener.config.IdleTimeout on requests)
UseReadHeaderTimeout(globalServerCtxt.ReadHeaderTimeout).
UseBaseContext(GlobalContext).
UseCustomLogger(log.New(io.Discard, "", 0)). // Turn-off random logging by Go stdlib