-
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
documentation: add stream lifecycle doc to NewStream #2060
Conversation
(very unfamiliar with proto-gen-go) I'm looking at pubsub.pb.go, one of our autogenerated clients. I assume this is generated with proto-gen-go. It does not appear to have any method-level comments. @dfawley wrt documenting ctx usage, did you have in mind putting some method-level comments on these generated files, or? |
@@ -101,7 +101,7 @@ type ClientStream interface { | |||
} | |||
|
|||
// NewStream creates a new Stream for the client side. This is typically | |||
// called by generated code. | |||
// called by generated code. ctx is used for the lifetime of the stream. |
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.
If you're making changes here, would you mind summarizing what I wrote in #1854 regarding how to ensure a stream doesn't leak a goroutine? Something like:
// To ensure resources are not leaked due to the stream returned, one of the following
// actions must be performed:
//
// 1. call Close on the ClientConn,
// 2. cancel the context provided,
// 3. call RecvMsg until a non-nil error is returned, or
// 4. receive a non-nil error from Header or SendMsg besides io.EOF.
//
// If none of the above happen, a goroutine and a context will be leaked, and grpc
// will not call the optionally-configured stats handler with a stats.End message.
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.
Done
stream.go
Outdated
@@ -114,7 +114,7 @@ func (cc *ClientConn) NewStream(ctx context.Context, desc *StreamDesc, method st | |||
} | |||
|
|||
// NewClientStream creates a new Stream for the client side. This is typically |
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.
How about
// NewClientStream is a wrapper for ClientConn.NewStream.
//
// DEPRECATED: ....
to avoid the need to duplicate documentation.
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.
Done
This adds documentation around how to properly close a stream, and how ctx is used by streams.