From 6fea5fba61bb97b8bc76408f28c0d3894faa25f7 Mon Sep 17 00:00:00 2001 From: "Tyler.S" Date: Tue, 7 Mar 2023 10:01:58 -0800 Subject: [PATCH] Added default WriteTimeout of 30s to HTTP server --- support/http/main.go | 6 ++++++ support/http/main_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/support/http/main.go b/support/http/main.go index 8decf90327..12212c2121 100644 --- a/support/http/main.go +++ b/support/http/main.go @@ -33,6 +33,8 @@ const defaultShutdownGracePeriod = 10 * time.Second const defaultReadTimeout = 5 * time.Second +const defaultWriteTimeout = 30 * time.Second + // SimpleHTTPClientInterface helps mocking http.Client in tests type SimpleHTTPClientInterface interface { PostForm(url string, data url.Values) (*stdhttp.Response, error) @@ -105,6 +107,10 @@ func setup(conf Config) *graceful.Server { conf.ReadTimeout = defaultReadTimeout } + if conf.WriteTimeout == time.Duration(0) { + conf.WriteTimeout = defaultWriteTimeout + } + return &graceful.Server{ Timeout: conf.ShutdownGracePeriod, TCPKeepAlive: conf.TCPKeepAlive, diff --git a/support/http/main_test.go b/support/http/main_test.go index 7f05255174..e184fcce4d 100644 --- a/support/http/main_test.go +++ b/support/http/main_test.go @@ -25,7 +25,7 @@ func TestRun_setupDefault(t *testing.T) { assert.Equal(t, defaultShutdownGracePeriod, srv.Timeout) assert.Equal(t, defaultReadTimeout, srv.ReadTimeout) - assert.Equal(t, time.Duration(0), srv.WriteTimeout) + assert.Equal(t, defaultWriteTimeout, srv.WriteTimeout) assert.Equal(t, time.Duration(0), srv.IdleTimeout) assert.Equal(t, defaultListenAddr, srv.Server.Addr) assert.Equal(t, time.Duration(0), srv.TCPKeepAlive)