-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix(i): Make peer connections deterministic #2888
fix(i): Make peer connections deterministic #2888
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2888 +/- ##
===========================================
- Coverage 79.40% 79.34% -0.06%
===========================================
Files 326 326
Lines 24870 24772 -98
===========================================
- Hits 19747 19655 -92
+ Misses 3716 3704 -12
- Partials 1407 1413 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 18 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
net/server.go
Outdated
@@ -196,7 +195,7 @@ func (s *server) addPubSubTopic(topic string, subscribe bool) error { | |||
} | |||
} | |||
|
|||
t, err := rpc.NewTopic(s.peer.ctx, s.peer.ps, s.peer.host.ID(), topic, subscribe) | |||
t, err := rpc.NewTopic(context.Background(), s.peer.ps, s.peer.host.ID(), topic, subscribe) |
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.
question: Are you sure this is an improvement? It does look like a suspicious change to me, I would have expected us to want to use the same context for all topics+peer
And the same goes for publishing to topics, and client.PushLog calls
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've always followed this rule from the Go docs:
Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it.
Since there is no context to pass around in these functions they should be run with a background context..
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.
In that case I really think we should ignore that suggestion here and use the context provided to the system. Please consider reverting this change a todo.
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 think the context provided to the constructor makes sense either since it would outlive the function call. Would you be okay with creating a new background context that is then used for all publish / topic calls?
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 think the context provided to the constructor makes sense either since it would outlive the function call.
Why does that not make sense? Any contextthing provided to a function outlives the function call
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.
suggestion: If you are not happy about this, I suggest we discuss it in the standup.
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 mean if I cancelled a context that I used to construct something, I'd want it to close all the things owned by that. I like that about the current setup.
If we didn't have explicit Start
and Stop
functions I would agree with this.
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.
If we didn't have explicit Start and Stop functions I would agree with this.
I could rant for quite a while about how much I hate Start
functions on objects with constructors... I don't see a Stop
function though, although I could rant about that/those paired with Close
functions too 😅.
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.
Interesting discussion, I feel like we have discussed something similar before. While I do personally have a slight preference for Andy's approach. Since I read the Go guidelines regarding not storing contexts in structs I do tend to stick to those guidelines and am happy with this change. However I do wonder if it's possible to just pass the ctx to addPubSubTopic
through a function parameter (most of the callers do have a ctx
).
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.
However I do wonder if it's possible to just pass the ctx to addPubSubTopic through a function parameter (most of the callers do have a ctx).
I'm open to this as long as that context is not the same as the constructor context.
@@ -24,6 +24,7 @@ type Options struct { | |||
EnableRelay bool | |||
GRPCServerOptions []grpc.ServerOption | |||
GRPCDialOptions []grpc.DialOption | |||
BootstrapPeers []string |
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.
question: Sorry if I've misread, but I can't spot where this is actually read - is it dead code?
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.
It's used here:
Line 84 in f8032b3
peers := make([]peer.AddrInfo, len(options.BootstrapPeers)) |
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.
cheers!
for i, p := range options.BootstrapPeers { | ||
addr, err := peer.AddrInfoFromString(p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.PrivateKey = key | ||
peers[i] = *addr | ||
} |
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.
question: This for-loop is never entered in any test, is it possible to test this easily?
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.
added a test for the non error case
// WithBootstrapPeers sets the bootstrap peer addresses to attempt to connect to. | ||
func WithBootstrapPeers(peers ...string) NodeOpt { | ||
return func(opt *Options) { | ||
opt.BootstrapPeers = peers | ||
} | ||
} |
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.
suggestion: All other config functions are tested in this file except this one. Please add a test if not too much hassle.
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.
added a test here
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.
Thanks for adding the requested tests, before merge please don't forget to handle the tidy
check (just need to do make tidy
) it's not required yet but will be nice to maintain a tidy state. Also do resolve the ctx
discussion before merging.
13254e8
to
bf38b6e
Compare
bf38b6e
to
1baf383
Compare
Relevant issue(s)
Resolves #2847
Resolves #1902
Description
This PR fixes an issue where peer connections were not deterministic within the test framework.
There's also a few other areas that were cleaned up:
net/host.go
net
package has been refactoredTasks
How has this been tested?
make test
Specify the platform(s) on which this was tested: