-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Server data race #4790
Server data race #4790
Conversation
a784034
to
fc06fcc
Compare
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.
Could you link the upstream patch please?
Let's wait a week or two, maybe it'll get accepted and we won't end up with yet another dependency fork.
b35a4f7
to
997bbc9
Compare
94c1b5b
to
1ed53d1
Compare
lib/reversetunnel/agent.go
Outdated
return | ||
} | ||
defer conn.Close() | ||
|
||
// Successfully connected to remote cluster. | ||
a.Infof("Connected to %s", conn.RemoteAddr()) | ||
a.log.WithField("addr", conn.LocalAddr().String()).WithField("remote-addr", conn.RemoteAddr().String()).Info("Connected.") |
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.
nit: use WithFields
to specify multiple fields at once
if !ok { | ||
return | ||
} | ||
*r = *s |
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.
The proto.Merger
docs say:
// Merge merges the contents of src into the receiver message.
// It clones all data structures in src such that it aliases no mutable
// memory referenced by src.
There are 2 possible issues:
- if
r.Foo
is set ands.Foo
is empty, I assume thatr.Foo
value should be preserved - if
Rotation
ever gets a pointer field, we break the promise of not keeping mutable memory references
I don't fully understand why we need to implement proto.Merger
. Does proto.Clone
not work on Rotation
otherwise?
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.
Can you link to the docs you reference, btw?
I know this is not the complete Merger implementation - it implements enough to support the Clone use-case so it assumes that the receiver is zero value. Unfortunately I was not able to find a concise way to implement it to fulfill the Merger requirements you described and yet be able to avoid exhaustive manual tests of each attribute which is exactly why I opted for Clone
.
Also, the Merger interface used here has a somewhat less strict requirement:
// Merge merges src into this message.
// Required and optional fields that are set in src will be set to that value in dst.
// Elements of repeated fields will be appended.
// ...
As to why I implemented Merger
also for Rotation
- exactly for the same reason as for Metadata
- b/c it was not working with reflect due to use of time.Time
which sports unexported fields.
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.
Ahh, I was looking at the regular protobuf docs, not gogoproto: https://github.com/golang/protobuf/blob/master/proto/proto.go#L99-L101
I think this merger implementation will cause problems later on, when it starts getting hit from non-Clone use-cases for whatever reason.
For now, it's OK to merge to fix the race, but leave a comment explaining that it's a partial implementation. Next person reading this code will appreciate the background :)
1ed53d1
to
bc24ed2
Compare
…after upstream PR.
bc24ed2
to
eff8742
Compare
eff8742
to
bee37d1
Compare
This PR fixes the data race I spotted the RoundRobin test.
What's interesting with this changeset is that it prompted a change in
gogo/protobuf
which I implemented in a temporary fork until the issue is resolved upstream.I've submitted a PR upstream.
Basically, protobuf package provides a reflect-based implementation of Clone. Attempting it on the Server type unfortunately in the version
v1.3.1
results in:Logs
Before the change:
Output
After the change:
Output
Fixes #4781.