You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Shutdown() does not wait for ExecuteCallback goroutines to complete #76
Shutdown() returns before all ExecuteCallback goroutines have finished. Any code that reads or modifies shared state immediately after Shutdown() returns can race with a still-running callback goroutine.
Steps to Reproduce
varresultstringclient:=amplitude.NewClient(amplitude.NewConfig("api-key"))
// set ExecuteCallback that writes to `result`
client.Track(...)
client.Shutdown()
fmt.Println(result) // data race: callback goroutine may still be writing
Running with go test -race reproduces the race.
Root Cause
In amplitudePlugin.Shutdown(), callbackWg.Wait() is only called in the happy path. When messageChannel is nil (e.g. after the internal start goroutine panics and defers messageChannel = nil), the function returns early without waiting for in-flight callbacks.
Fix
Call callbackWg.Wait() in the early-return path so all code paths guarantee callbacks have completed before Shutdown() returns.
Fix the regression test: the original test inadvertently established a happens-before chain (write → close → receive → read) that prevented the race detector from ever firing on unfixed code. Swapping the order (close before write) removes the false synchronization.
Activity