Skip to content

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

@seh

Description

@seh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions