launchdarkly / go-server-sdk

LaunchDarkly Server-side SDK for Go
Other
40 stars 17 forks source link

fix: resolve data race in Broadcasters system #153

Closed cwaldren-ld closed 1 month ago

cwaldren-ld commented 1 month ago

This resolves a data race in the Broadcaster implementation, specifically HasListeners() was not protected by a lock.

Additionally it swaps out the mutex for a RWLock so that concurrent readers don't block each other.

A behavioral change is that the Broadcast method now locks the subscribers array, so that Add or RemoveListener cannot be called concurrently.