Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support/http - Added default WriteTimeout of 30s to HTTP server #4796

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions support/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion support/http/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't wrong, but it also doesn't verify that for a non-zero config value, the same value is being set.

assert.Equal(t, time.Duration(0), srv.IdleTimeout)
assert.Equal(t, defaultListenAddr, srv.Server.Addr)
assert.Equal(t, time.Duration(0), srv.TCPKeepAlive)
Expand Down