-
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
Update documentation of stream interfaces using generics and remove code generation of stream methods in service interfaces #1894
Comments
There is a manual for our generated code on grpc.io, but I agree we should have better godocs or pointers to the manual from the generated code. |
So it's not really possible to do send and receive both from the same goroutine? I recently did an implementation of a notification system using bidirectional streams (where the client could change the topics it is interested in via messages and the server sends notifications over the stream). I ended up having a small goroutine putting incoming messages on a channel manually: So that I had a single goroutine that can do both sending and receiving with a select (sending on incoming notifications via a channel). It seems that I should exclude io.EOF in that small goroutine from closing the channel. So that the client can still receive notifications when it no longer wants to change it's subscription. Or explicitly document that the server closes the stream when the client does. (Seems a lot easier for the client as well, since otherwise canceling a stream needs to be done by cancelling a context..) |
Right, this is not recommended (but it is technically possible if you control both server and client and can ensure they work together properly).
Either way seems reasonable for this use case. I don't think there's much value in calling |
@srini100, note that we've recently added some stream documentation here: https://github.com/grpc/grpc-go/blob/master/Documentation/concurrency.md Is that sufficient for all of these issues? |
@dfawley I'd primarily like code documentation on the generated methods. So that I can read it (1) from godocs and (2) from going into the code with my IDE. Mostly the 2nd is where I was missing it. When you're implementing your server, you are using these interfaces. So it's normal that you want to go look at the documented behavior of them, right? Right now you get nothing. |
This issue is labeled as requiring an update from the reporter, and no update has been received after 7 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
There are still some things that could be clarified more about
Can we clarify what errors and how they should be handled may |
@purnesh42H Please assign me this issue. |
@janardhanvissa recently the implementations for streams are modified to use generics #7057, which will cause the gRPC codegen to use prebuilt generic types to implement client and server stream objects, rather than generating new types and implementations for every RPC method So, most of the above discussion is not relevant anymore. For now, you can add inline comments to stream interfaces's methods following the documentation here https://grpc.io/docs/languages/go/generated-code/ @dfawley to confirm if that is enough for this task |
+1. The medium-term plan is now to completely delete these generated interfaces in favor of the generics (they are still optionally generated for now). We should make sure the generics are well documented and make sure the generated code has enough information to help users understand them. We should also update the grpc.io doc @purnesh42H pointed to as needed. Another thing I noticed yesterday is that it doesn't mention the embedding of the |
@purnesh42H, I have added the behavior of the function "RouteChat" and generated the protobuf files. I have raised a PR for the changes that made. Please review the PR and let us know if any changes are required for the ticket. Please find the PR below. |
@janardhanvissa the PR is not addressing the requirements of this task. As mentioned above, the implementations for streams are modified to use generics #7057, so we need to document the stream interfaces in generics. Here are the high level tasks that needs to be done.
Let's modify the PR you sent for 1) and then we will move to 2) and 3) |
FWIW this is not correct. Generated code should never be directly modified. It should be regenerated when the generator or source files change, which our vet-proto checker will fail if we don't do that correctly. |
@purnesh42H Added Inline comments for all the 6 interfaces in stream_interfaces.go. Please find the PR below. Also please provide the brief information regarding 2) and 3) as mentioned above. |
@purnesh42H I removed the parent interface inline comments as mentioned. Could you please provide the brief information regarding 2) and 3) as mentioned.
|
@purnesh42H - you reopened this -- what still needs to be done here? |
yeah, don't we still have to do these 2?
|
Sure. Maybe we can update the title of the issue to include these things, too? We added documentation to the generic interfaces, so from the title it seems like we're done here. |
Updated |
We will need to update the documentation to remove the part that says that we can go back to old behavior by changing the flag, when we remove the flag and make the use of stream generics default |
For a bi-directional stream, I get the following generated code:
There is absolutely no documentation about the behavior of these methods. They should either be documented in the code, or have a link to a page with documentation about them.
The "Go Basics" documentation merely gives the following example code:
It seems that it's impossible to get a channel for incoming messages. But it's also not clear if
Recv
is a blocking call. Doesio.EOF
mean that the client closed that channel or that there is currently nothing to be read?UPDATE:
Implementations for streams are modified to use generics #7057, which will cause the gRPC codegen to use prebuilt generic types to implement client and server stream objects, rather than generating new types and implementations for every RPC method. We need to make sure the stream interfaces using generics are well documented. Here are the high level tasks for completion
The text was updated successfully, but these errors were encountered: