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

p2p: support zero length request protos #1958

Merged
merged 2 commits into from
Mar 29, 2023
Merged

Conversation

corverroos
Copy link
Contributor

Fix regression introduced by length-delimited upgrades which assumed that legacy-stream-delimited protocols handled requests and responses the same while it didn't. It allowed zero length requests while it didn't allow zero-length responses. This aligns the new implementation with that.

category: bug
ticket: #1956

@@ -223,10 +223,19 @@ func SendReceive(ctx context.Context, tcpNode host.Host, peerID peer.ID,
return errors.Wrap(err, "close write", z.Any("protocol", s.Protocol()))
}

zeroResp := proto.Clone(resp)
Copy link
Contributor

Choose a reason for hiding this comment

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

what if resp is NOT a zero/empty response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, that is an edge-case not handled by this code

Copy link
Contributor Author

@corverroos corverroos Mar 29, 2023

Choose a reason for hiding this comment

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

but that would be a bug in the code that uses this function, so a build-time issue, not a run-time issue. We can look at adding some build-time checks that all passed in responses are zero.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see, for the time being, we can probably edit the godoc of this function to say that Callers of this method should ensure that the resp parameter is zero/empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a isZeroProto check to the SendReceive function.

@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Patch coverage: 71.42% and project coverage change: +0.34 🎉

Comparison is base (e8931f5) 55.45% compared to head (5ebb973) 55.79%.

❗ Current head 5ebb973 differs from pull request most recent head 26c350a. Consider uploading reports for the commit 26c350a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1958      +/-   ##
==========================================
+ Coverage   55.45%   55.79%   +0.34%     
==========================================
  Files         174      174              
  Lines       22297    22300       +3     
==========================================
+ Hits        12365    12443      +78     
+ Misses       8361     8277      -84     
- Partials     1571     1580       +9     
Impacted Files Coverage Δ
p2p/sender.go 71.42% <71.42%> (-1.30%) ⬇️

... and 8 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -223,10 +223,19 @@ func SendReceive(ctx context.Context, tcpNode host.Host, peerID peer.ID,
return errors.Wrap(err, "close write", z.Any("protocol", s.Protocol()))
}

zeroResp := proto.Clone(resp)

if err = reader.ReadMsg(resp); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will still return the errors that we are seeing in logs:
Peerinfo failed: read response: peer errored, no response

how is this allowing zero length responses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See legacyReadWriter ReadMsg

return errors.Wrap(err, "read response")
} else if len(b) == 0 {
return errors.New("peer errored, no response")
return errors.Wrap(err, "read proto")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dB2510 this was the zero length check that was erroring, it has been removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it!

//
// Note this function is inefficient for the negative case (i.e. when the message is not zero)
// as it copies the input argument.
func isZeroProto(m proto.Message) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label Mar 29, 2023
@obol-bulldozer obol-bulldozer bot merged commit 539c34f into main Mar 29, 2023
@obol-bulldozer obol-bulldozer bot deleted the corver/p2pzerolen2 branch March 29, 2023 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants