@@ -45,9 +45,11 @@ const (
4545 maxMultipartMemory = 1 << 27 // 128 MiB
4646 maxUploadLimit = 1 << 28 // 256 MiB
4747
48- maxReadHeaderTimeout = 60 * time .Second
49- maxReadTimeout = 75 * time .Second
50- maxWriteTimeout = 75 * time .Second
48+ maxReadTimeout = 75 * time .Second
49+ maxWriteTimeout = 75 * time .Second
50+ // This timeout should be > 600 (GCP LB upstream idle timeout) to prevent race condition
51+ // https://cloud.google.com/load-balancing/docs/https#timeouts_and_retries%23:~:text=The%20load%20balancer%27s%20backend%20keepalive,is%20greater%20than%20600%20seconds
52+ idleTimeout = 620 * time .Second
5153
5254 defaultPort = 80
5355)
@@ -171,12 +173,13 @@ func NewGinServer(ctx context.Context, logger *zap.Logger, apiStore *handlers.AP
171173 r .MaxMultipartMemory = maxMultipartMemory
172174
173175 s := & http.Server {
174- Handler : r ,
175- Addr : fmt .Sprintf ("0.0.0.0:%d" , port ),
176- ReadHeaderTimeout : maxReadHeaderTimeout ,
177- ReadTimeout : maxReadTimeout ,
178- WriteTimeout : maxWriteTimeout ,
179- BaseContext : func (net.Listener ) context.Context { return ctx },
176+ Handler : r ,
177+ Addr : fmt .Sprintf ("0.0.0.0:%d" , port ),
178+ // Configure timeouts to be greater than the proxy timeouts.
179+ ReadTimeout : maxReadTimeout ,
180+ WriteTimeout : maxWriteTimeout ,
181+ IdleTimeout : idleTimeout ,
182+ BaseContext : func (net.Listener ) context.Context { return ctx },
180183 }
181184
182185 return s
0 commit comments