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

UpdateApp assigning a struct from a goroutine is not safe #36

Open
seh opened this issue Mar 11, 2016 · 2 comments
Open

UpdateApp assigning a struct from a goroutine is not safe #36

seh opened this issue Mar 11, 2016 · 2 comments

Comments

@seh
Copy link
Contributor

seh commented Mar 11, 2016

The UpdateApp method on EurekaConnection starts a goroutine that periodically unmarshals a new Application value, and then assigns it wholesale to an Application that represented the previous version of that Eureka application.

Per my note in file net.go, such assignment is not safe without either synchronization or use of atomic store and load operations. It's possible for a goroutine reading the Application value submitted to UpdateApp to observe a corrupted value. Per The Go Memory Model,

Reads and writes of values larger than a single machine word behave as multiple machine-word-sized operations in an unspecified order.

Since we can't orchestrate all the reads of the Application value submitted to UpdateApp, I suggest instead that UpdateApp offer a single-valued buffered channel from which interested clients can receive updates.

@seh
Copy link
Contributor Author

seh commented Apr 8, 2016

Now that #37 is merged, should we consider deprecating the UpdateApp method?
That would involve a change to the documentation, as we'd have to leave the method in place to avoid stranding existing callers.

@itsrainy
Copy link
Contributor

itsrainy commented Apr 8, 2016

Yep, we'll definitely want to leave that method in place, but the example in the readme should be updated as well as the documentation for that method in connection.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants