hudl / fargo

Golang client for Netflix Eureka
MIT License
133 stars 53 forks source link

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

Open seh opened 8 years ago

seh commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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