Skip to content
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

Merged
merged 3 commits into from
Jun 27, 2018

Conversation

jeanbza
Copy link
Member

@jeanbza jeanbza commented Jun 22, 2018

Relevant issue: #2159

@jeanbza jeanbza requested review from MakMukhi and dfawley June 22, 2018 21:02
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
Copy link
Contributor

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.);

  1. Client creates a stream(headers are sent to the server)
  2. Client sends data(potentially more than one message)
  3. Server sends headers.
  4. Server sends data(potentially more than one message)
  5. Client sends end of stream.
  6. Server sends trailers(status).
  7. Client receives EOF/error.

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

@jeanbza
Copy link
Member Author

jeanbza commented Jun 27, 2018

Did a final round of cleanup. (no real content change) Does this look ok?

screen shot 2018-06-27 at 4 46 22 pm

@MakMukhi
Copy link
Contributor

LGTM

@jeanbza jeanbza merged commit f9bde86 into grpc:master Jun 27, 2018
@dfawley
Copy link
Member

dfawley commented Jun 27, 2018

SendMsg does not return an RPC status -- it returns io.EOF and the client needs to call RecvMsg to determine the status.

"To ensure delivery..." should end with "before cancelling the context" instead of "before closing the stream". (The stream is already closed when RecvMsg returns io.EOF and it's not necessary to cancel the context after then - but it's still a good idea anyway.)

@jeanbza
Copy link
Member Author

jeanbza commented Jun 27, 2018

Shoot. I just hit squash and merge. I can open a new PR to fix those comments @dfawley.

@jeanbza
Copy link
Member Author

jeanbza commented Jun 27, 2018

#2184

@dfawley dfawley added the Type: Documentation Documentation or examples label Jun 28, 2018
@dfawley dfawley added this to the 1.14 Release milestone Jun 28, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Documentation Documentation or examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants