Skip to content

Commit

Permalink
Add HTTP Shutdown Timeout (#151)
Browse files Browse the repository at this point in the history
* add shutdown timeout

* re-enable helper
  • Loading branch information
sethjback authored Sep 6, 2023
1 parent ca6cd12 commit 3844cac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions surveyor/conn_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestConnPool(t *testing.T) {
t.Parallel()

s := natsservertest.RunRandClientPortServer()
defer s.Shutdown()
o1 := &natsContext{
Expand Down
4 changes: 3 additions & 1 deletion surveyor/surveyor.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ func (s *Surveyor) Stop() {
}

if s.httpServer != nil {
_ = s.httpServer.Shutdown(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
_ = s.httpServer.Shutdown(ctx)
s.httpServer = nil
}

Expand Down
4 changes: 2 additions & 2 deletions surveyor/surveyor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func httpGetSecure(url string) (*http.Response, error) {
return nil, err
}
transport := &http.Transport{TLSClientConfig: tlsConfig}
httpClient := &http.Client{Transport: transport, Timeout: 30 * time.Second}
httpClient := &http.Client{Transport: transport, Timeout: 3 * time.Second}
return httpClient.Get(url)
}

Expand All @@ -70,7 +70,7 @@ func parseTLSConfig(certFile, keyFile, caFile string) (*tls.Config, error) {
}

func httpGet(url string) (*http.Response, error) {
httpClient := &http.Client{Timeout: 30 * time.Second}
httpClient := &http.Client{Timeout: 3 * time.Second}
return httpClient.Get(url)
}

Expand Down

0 comments on commit 3844cac

Please sign in to comment.