-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: clarify SendMsg documentation #2171
Conversation
Relevant issue: grpc#2159
stream.go
Outdated
// by default - can cause messages to be lost. To ensure delivery, | ||
// users must call RecvMsg until receiving an EOF before closing the | ||
// stream. | ||
// | ||
// On error, it aborts the stream and returns an RPC status on client |
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 was actually thinking about it this morning. A documentation like this seems confusing given that a stream ends only with receiving either an EOF or an Error. From a user's point of view when or if a message is delivered should be opaque.
Perhaps the documentation that we need is a stream's life cycle (if it doesn't already exist.);
- Client creates a stream(headers are sent to the server)
- Client sends data(potentially more than one message)
- Server sends headers.
- Server sends data(potentially more than one message)
- Client sends end of stream.
- Server sends trailers(status).
- Client receives EOF/error.
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.
A documentation like this seems confusing given that a stream ends only with receiving either an EOF or an Error.
I don't follow, could you elaborate? That detail is what this documentation attempts to address.
From a user's point of view when or if a message is delivered should be opaque.
That would only be possible if individual messages (not frames) were acked. But, since they aren't, I don't think we can get around informing folks that they must wait for EOF or risk losing messages.
Perhaps the documentation that we need is a stream's life cycle
I think that would be valuable, but is separate from / not mutually exclusive with this 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.
I don't follow, could you elaborate? That detail is what this documentation attempts to address.
What I mean is perhaps changing the documentation from "it blocks until the message is sent" to "blocks until a message is scheduled" makes more sense, rather than warning users of what unexpected behavior may occur in the current implementation if they don't use the API right.
We bind a stream's context to all operations happening on that stream, if the context is canceled then no further operations can happen on it. Further, for a client stream to only send messages and not read a status is incorrect usage. I see the motivation to inform users that a send call doesn't block until the whole message is written to the wire, but more importantly they shouldn't be cancelling streams' context without reading an EOF or error.
Does that make sense?
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.
My two goals:
- Remove the assumption that the message is delivered after calling SendMsg.
- Educate users that until they receive EOF, their message may not have been delivered. SendMsg seems a natural place to put an abbreviated warning about this since users expecting ack behavior are likely to look at SendMsg documentation.
What I mean is perhaps changing the documentation from "it blocks until the message is sent" to "blocks until a message is scheduled" makes more sense, rather than warning users of what unexpected behavior may occur in the current implementation if they don't use the API right.
Done, PTAL.
LGTM |
"To ensure delivery..." should end with "before cancelling the context" instead of "before closing the stream". (The stream is already closed when |
Shoot. I just hit squash and merge. I can open a new PR to fix those comments @dfawley. |
Relevant issue: #2159