-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transport): configure HTTP/2 ReadIdleTimeout (#882)
Setting this config causes the HTTP/2 transport to send a ping on idle connections every 15s and prune ones that have been severed. This should give increased reliability during network issues between the client and CFE.
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2021 Google LLC. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build go1.16 | ||
|
||
package http | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"golang.org/x/net/http2" | ||
) | ||
|
||
// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the | ||
// transport. This allows broken idle connections to be pruned more quickly, | ||
// preventing the client from attempting to re-use connections that will no | ||
// longer work. | ||
func configureHTTP2(trans *http.Transport) { | ||
http2Trans, err := http2.ConfigureTransports(trans) | ||
if err == nil { | ||
http2Trans.ReadIdleTimeout = time.Second * 15 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2021 Google LLC. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !go1.16 | ||
|
||
package http | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the | ||
// transport. The interface to do this is only available in Go 1.16 and up, so | ||
// this performs a no-op. | ||
func configureHTTP2(trans *http.Transport) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters