Skip to content

Commit

Permalink
fix: don't panic if envContext is closed twice (#417)
Browse files Browse the repository at this point in the history
It was possible for `Close()` to be invoked concurrently, which would
cause a data race on some of the cleanup tasks (including closing other
channels.)

This specifically fixes a panic when using a combination of
`exitAlways=1` and `ignoreConnectionErrors=1`.
  • Loading branch information
cwaldren-ld committed Aug 5, 2024
1 parent d6d6001 commit 36f3168
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/relayenv/env_context_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type envContextImpl struct {
doneMonitoringCredentials chan struct{}
connectionMapper ConnectionMapper
offline bool
closed bool
}

// Implementation of the DataStoreQueries interface that the streams package uses as an abstraction of
Expand Down Expand Up @@ -701,6 +702,11 @@ func (c *envContextImpl) FlushMetricsEvents() {

func (c *envContextImpl) Close() error {
c.mu.Lock()
if c.closed {
c.mu.Unlock()
return nil
}
c.closed = true
for _, client := range c.clients {
_ = client.Close()
}
Expand Down

0 comments on commit 36f3168

Please sign in to comment.