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
feat(transport): configure HTTP/2 ReadIdleTimeout #882
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cdef3a6
feat(transport): configure HTTP/2 ReadIdleTimeout
tritone abdad9c
use build tags and add docs
tritone a81f9bd
gofmt
tritone 8e0a004
go mod tidy
tritone fcf5b81
Merge branch 'master' into http2-readidletimeout
tritone 6073e69
go mod tidy
tritone File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something, but should we be using
ConfigureTransport
? Or ishttp2Trans
magically connecting some pointers under the hood. I guess I don't understand how the setting on line 23 will do anything totrans
, am I missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked Damien the same question and he confirmed that this is how it's supposed to be done. Unfortunately
ConfigureTransport
does not actually give you access to the underlying surface. @neild can you comment on how this works under the hood?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http2.ConfigureTransport
just callshttp2.ConfigureTransports
and discards the*Transport
.ConfigureTransports
is a newer function added to allow modifying thehttp2.Transport
configuration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neild Right, I do understand this provides some toggles to configure settings. What I was trying to ask is should this method, configureHTTP2, should be returning http2Trans as a RoundTripper? But it look like this transport is embedded into
trans
via RegisterProtocol now that I look a little closer. Would there be any benefit returning http2Trans though?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified via local testing with
http2debug=1
that a storage client created using this does, in fact, send a PING every 15s.