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: fix a bug introduced in #7461 #7505

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Aug 13, 2024

When I was reviewing #7461, I made a comment to replace some lines which read as:

err = foo()
if err == nil { ... }

to be replaced as:

if err := foo(); err == nil { ... }

Little did I realize that the err value was being used below. Luckily this did not make it into the release, which we haven't yet cut. So, no release notes required.

This wasn't caught as a compile error, because err was a named return parameter. I'm not making the changes in this PR to not have err as a named return parameter though.

RELEASE NOTES: none

@easwars easwars requested a review from dfawley August 13, 2024 18:55
@easwars easwars added this to the 1.66 Release milestone Aug 13, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 81.52%. Comparing base (ced812e) to head (f4e8daa).

Files Patch % Lines
stream.go 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7505      +/-   ##
==========================================
- Coverage   81.58%   81.52%   -0.06%     
==========================================
  Files         358      358              
  Lines       27388    27390       +2     
==========================================
- Hits        22345    22331      -14     
- Misses       3828     3836       +8     
- Partials     1215     1223       +8     
Files Coverage Δ
stream.go 81.77% <50.00%> (+0.28%) ⬆️

... and 16 files with indirect coverage changes

stream.go Outdated
@@ -1121,7 +1121,8 @@ func (a *csAttempt) recvMsg(m any, payInfo *payloadInfo) (err error) {
}
// Special handling for non-server-stream rpcs.
// This recv expects EOF or errors, so we don't collect inPayload.
if err := recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, nil, a.decomp, false); err == nil {
err = recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, nil, a.decomp, false)
Copy link
Member

Choose a reason for hiding this comment

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

How about something like this instead:

if err := recv(); err == io.EOF {
	return a.s.Status().Err() // expected; return stream status error
} else if err != nil {
	return toRPCErr(err) // other error
}
return ...gOt <nil>, wanted io.EOF... // no end stream??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
return toRPCErr(err)
return toRPCErr(errors.New("grpc: client streaming protocol violation: get <nil>, want <EOF>"))
Copy link
Member

Choose a reason for hiding this comment

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

*gOt please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Didn't see this comment in the excitement to merge this :(

@easwars easwars merged commit 5c4da09 into grpc:master Aug 13, 2024
11 checks passed
@easwars easwars deleted the err_inlining_error branch August 13, 2024 21:34
infovivek2020 pushed a commit to infovivek2020/grpc-go that referenced this pull request Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants