From 155ed972b589dfbba22c084f61c2de7e171d51b8 Mon Sep 17 00:00:00 2001 From: Erick Pintor Date: Tue, 23 Apr 2024 12:29:43 -0300 Subject: [PATCH] ENG-6200: Turn client timeout into a response header timeout (#138) --- client.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index ff1f5a3..4ac9e40 100644 --- a/client.go +++ b/client.go @@ -132,15 +132,21 @@ func NewClient(secret string, timeouts Timeouts, configFns ...ClientConfigFn) *C Timeout: timeouts.ConnectionTimeout, } + // NOTE: prefer a response header timeout instead of a client timeout so + // that the client don't stop reading a http body that was produced by + // Fauna. On the query interface, an HTTP body is sent as a single http + // message. On the streaming interface, HTTP chunks are sent on every event. + // Therefore, it's in the driver's best interest to continue reading the + // HTTP body once the headers appear. httpClient := &http.Client{ Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: dialer.DialContext, - ForceAttemptHTTP2: true, - MaxIdleConns: 20, - IdleConnTimeout: timeouts.IdleConnectionTimeout, + Proxy: http.ProxyFromEnvironment, + DialContext: dialer.DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 20, + IdleConnTimeout: timeouts.IdleConnectionTimeout, + ResponseHeaderTimeout: timeouts.QueryTimeout + timeouts.ClientBufferTimeout, }, - Timeout: timeouts.QueryTimeout + timeouts.ClientBufferTimeout, } defaultHeaders := map[string]string{