-
Notifications
You must be signed in to change notification settings - Fork 213
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 data race in params.Entries chan #75
base: main
Are you sure you want to change the base?
Conversation
51bc674
to
d7f8d26
Compare
According to whyrusleeping#4 (comment) this isn't the right fix for this problem? |
By copying the other thread won't be able to reference |
Well no. Other fields are affected by data race too. So you either have to use mutex to access fields (like in whyrusleeping#4) or copy the value and send it. |
Only one field is called out in this PR though. If other fields are affected too, shouldn't they also be addressed? |
No because I copy the value and send it to another thread. So having |
What's wrong with protecting the fields with a mutex like they did in whyrusleeping? I don't really know the code, but that seems to have less potential knock on effects than changing whether the original object or a copy are sent. Especially given some fields (e.g. InfoFields, and potentially other fields in the future) are reference values. |
You have to ensure the end user to lock the mutex (via protected fields and accessors). It will break the existent code for your users.
It will have an opposite effect. You store Please read |
Will it? At worst if they are accessing things directly they will be no worse off than they are now. At best they'll use the mutexes. |
Or in my case they don't need mutexes at all. Isn't it perfect? |
Depends on the knock-on effects of using a copy instead of the original values, which I'm unclear on. |
https://golang.org/ref/mem#tmp_6
Which means that no matter what logic you have in your code having data race makes it incorrect. Fix the data race. And then fix your logic. |
Sorry, I'm not following what you mean there. |
I am telling you that a code without data race is better than a code with a data race. |
We can agree on that, yes. |
So let's merge this PR. |
Sorry, I can't. I don't know the ramifications of making that change. Someone that knows the library better than me would have to evaluate that. Or it can be fixed in a way that doesn't change the object being sent down the channel, in which case I'd be comfortable merging. |
Is not the only ramification that clients will get multiple messages on the channel for the same discovered service? That might be considered a breaking change, but I don't think this can be solved without making a breaking change.
Are you referring to the If you still would like to keep it, would be it be acceptable to just set it to |
A solution from whyrusleeping#4 (comment)
Other solutions can be:
func ensureName
if inp from inprogress is already sentinprogress
before sending to channelBefore:
After: