Merged
Conversation
context, and defer in it's calling. This is done so that there can be asynchronous calls that spawn off of the Server side that can inherit from the given context.Context.
Contributor
Author
|
Something I feel I should point out, is that in the case of streaming, which is something you had brought up earlier, the underlying http connection is hijacked (in the case of changed protocols) and in those cases the Server's context will be cancelled as well: https://github.com/golang/go/blob/master/src/net/http/server.go#L1561-L1563 |
Member
|
This is just pending the same changes applied to gRPC, if I understand correctly. |
Contributor
Author
|
From what I see, this is targeting all of the Serve methods in each of the transports. Did I miss one? Or are you referring to the two separate contexts that are being used currently in the ServeGRPC? Should we unify them, so that everything is just using the context that is passed in? |
Member
|
Ah! You're right. I'm silly. Thank you! |
Ayiga
pushed a commit
to Ayiga/kit
that referenced
this pull request
Jul 4, 2016
[WIP] Transports and contexts
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
remove creation and call of server.Serve method's context.WithCancel.
In this initial commit I believe it would be in the interest of flexibility to not force the creation and immediate cancellation of the context that is spawned from the server.
This cancellation prevents the ability to fire an asynchronous request that inherits from the same context that was given for the Serve request.
However, I believe that may warrant further discussion, as in the golang 1.7 release there will be a context that will likely be inherited from in a future change to go-kit, that will cancel the underlying context when the client's connection is closed:
https://github.com/golang/go/blob/master/src/net/http/server.go#L1508-L1509
This is also the case with client-side connection as well in the new DialContext method
https://github.com/golang/go/blob/master/src/net/dial.go#L308-L309
In both of these cases the context lives for the life-time of the connection. However, there is an important distinction. On the client side, the context is inherited from the context that is passed in. This means that when the context is cancelled, it will only cancel down the context inheritance stack, which is only the context that they've created. However, in the server side implementation, everything is inherited directly from the Connection handling / delivery with golang's
net/httpconn.servemethod.For Example the output of the following program
is the following:
Perhaps this means that overall context utilization may need to be reconsidered on the Server, as any inheritance from the net/http's conn.serve method's context will be canceled and invalidated on client connection close.
In the mean time, I'd also like to consider the removal of the context extension / cancellation in the client transport methods as well. However, these hardly have much of a bearing, and I don't think they affect logic / asynchronous calls one way or another.
https://github.com/go-kit/kit/blob/master/transport/grpc/client.go#L77-L78
https://github.com/go-kit/kit/blob/master/transport/http/client.go#L80-L81