-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
transport: add peer information to http2Server and http2Client context #5589
transport: add peer information to http2Server and http2Client context #5589
Conversation
|
Looks like the failed test case is a known flake test: Test/DetailedGoawayErrorOnGracefulClosePropagatesToRPCError How can I rerun the build? |
This reverts commit 4a55ac5.
All tests have passed, but LABEL and MILESTONE I don't have permission to add. Thanks |
Thanks for the PR. Did you intend to do this only for the server, and not for the client? If so, why? And could you please add tests for this. |
internal/transport/http2_server.go
Outdated
s.ctx = peer.NewContext(s.ctx, pr) | ||
|
||
// Add peer information to the stream context. | ||
s.ctx = peer.NewContext(s.ctx, t.getPeer()) |
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.
Since this is derived from the transport's context (immediately above), we shouldn't need to re-attach the peer here.
Will update PR accordingly |
Updated:
Not feeling confident to make the same change for client due to my limited understand of client side code, also unlike server context which is initiated from scratch, an external context is passed into client constructor, so I am concerned about isolation of that chagne. |
internal/transport/http2_server.go
Outdated
pr := &peer.Peer{ | ||
Addr: t.remoteAddr, | ||
} | ||
// Attach Auth info if there is any. | ||
if t.authInfo != nil { | ||
pr.AuthInfo = t.authInfo | ||
} | ||
return pr |
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.
This can probably be simplified as:
return &peer.Peer{
Addr: t.remoteAddr,
AuthInfo: t.authInfo, // Can be nil.
}
internal/transport/transport_test.go
Outdated
@@ -2450,3 +2452,20 @@ func TestConnectionError_Unwrap(t *testing.T) { | |||
t.Error("ConnectionError does not unwrap") | |||
} | |||
} | |||
|
|||
// Verify Peer is set in server context. | |||
func TestPeerSetInServerContext(t *testing.T) { |
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.
Please specify our test struct as the receiver for this test. This will ensure that our leakcheck runs at the end of the test.
func (s) TestPeerSetInServerContext(t *testing.T) { ... }
internal/transport/transport_test.go
Outdated
|
||
// Verify Peer is set in server context. | ||
func TestPeerSetInServerContext(t *testing.T) { | ||
server := setUpServerOnly(t, 0, &ServerConfig{}, suspended) |
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.
setUpServerOnly
does not setup any transports. So, server.conns
in your for
loop will be nil
, and therefore this test will not be doing anything.
You either need to use setUpWithOptions
or you need to explicitly do a net.Dial()
to create a transport. Please see some other tests in the same file to get a better idea. Thanks.
internal/transport/transport_test.go
Outdated
for k := range server.conns { | ||
sc, ok := k.(*http2Server) | ||
if !ok { | ||
t.Fatalf("Failed to convert %v to *http2Server", k) |
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.
Would be nice to include the actual type as well:
t.Fatalf("ServerTransport is of type %T, want %T, k, &http2Server{})
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.
awesome!
internal/transport/transport_test.go
Outdated
_, ok = peer.FromContext(sc.ctx) | ||
if !ok { |
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.
These two lines can be combined into one.
@easwars really appreciated for your review. Will update and respond individually. |
The main difference is: on the server, the stream's context is a child of the transport's context, whereas in the client, the stream's context is what the user provides for that RPC instead. It should be fine to attach the peer information on the transport's context as well as the stream's context, but note that we would have to do it in both places on the client. |
|
internal/transport/transport_test.go
Outdated
|
||
// verify peer is set in server transport context. | ||
count := 0 | ||
for { |
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.
You could use the waitWhileTrue
helper method to simplify the waiting logic here. See : https://github.com/grpc/grpc-go/blob/master/internal/transport/transport_test.go#L1616
apologize, missed that error. |
Is there a recommended way to rerun the CI build? I believe these are unrelated errors. |
Thank you for the PR! |
Motivation: #5586
Added peer to the http2server context to allow application to access this information when a connection is just established. This frees application from tracking this information on each and every rpc request.
RELEASE NOTES:
HandleConn
context