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

grpc: document ctx closure best practices #600

Merged
merged 5 commits into from
May 11, 2018

Conversation

jeanbza
Copy link
Member

@jeanbza jeanbza commented May 11, 2018

Corresponding grpc PR: grpc/grpc-go#2060

@jeanbza
Copy link
Member Author

jeanbza commented May 11, 2018

@dfawley

Copy link
Contributor

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up!

When you're done, you will also need to regenerate the proto files (check travis failures).

@@ -303,6 +303,19 @@ func (g *grpc) generateClientMethod(servName, fullServName, serviceDescVar strin
if method.GetOptions().GetDeprecated() {
g.P(deprecationComment)
}
streamType := unexport(servName) + methName + "Client"
g.P(fmt.Sprintf(`// The ctx passed in will be used for the lifetime of this object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a godoc-compliant comment.

// <method> initiates a new streaming RPC to the server, yadda yadda.

However, the type that owns this method is not exported (unexport(servName) below). This should be documented in the interface instead, or else it will never be seen. Note that those include the comments from the proto file, so we'll have to be smart about how to keep pulling those in but also document the Go implementation as well.

@jeanbza
Copy link
Member Author

jeanbza commented May 11, 2018

@dfawley PTAL - moved to interface, use pointer instead of dupe doc

g.P()
g.P(fmt.Sprintf(`// Client API for %s service.
//
// For semantics around ctx use and closing/ending RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.`, servName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "closing/ending streaming RPCs".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jeanbza
Copy link
Member Author

jeanbza commented May 11, 2018

@dsnet Could you describe what the problem with travis is? It seems to be stuck on some commit?

@dfawley
Copy link
Contributor

dfawley commented May 11, 2018

@jadekler I'm pretty sure you need to regenerate these pb.go files and commit them along with this PR, as you've changed how they are generated.

@jeanbza
Copy link
Member Author

jeanbza commented May 11, 2018

Aha - thanks, done.

@@ -160,8 +160,9 @@ func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.Servi
deprecated := service.GetOptions().GetDeprecated()

g.P()
g.P("// Client API for ", servName, " service")
g.P()
g.P(fmt.Sprintf(`// Client API for %s service.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://golang.org/doc/effective_go.html#commentary, this should probably be written as:

// TestClient is the client API for the Test service.
//
// For semantics around resource cleanup, please refer to
// https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn't a similar comment be on the server equivalent of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

And, although I think you're right, the server's case + recommendations are different and should probably live in a different PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine with me.

g.P()
g.P(fmt.Sprintf(`// Client API for %s service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.`, servName))

// Client interface.
if deprecated {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put a newline before the deprecation comment:

g.P("\n"+deprecationComment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dsnet dsnet added the grpc label May 11, 2018
@dsnet
Copy link
Member

dsnet commented May 11, 2018

Changes LGTM, but you'll need to regenerate the protos again.

@jeanbza
Copy link
Member Author

jeanbza commented May 11, 2018

Shoot, good point. Done.

@dsnet dsnet merged commit 32a84b2 into golang:master May 11, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants