Skip to content

Commit

Permalink
fix: heartbeat go routine gone rogue (#1030)
Browse files Browse the repository at this point in the history
When running integration tests with high concurrency, race warnings
frequently appeared, often triggered by the heartbeat. It seems that
after some refactoring, a goroutine was left behind without any
synchronization mechanism, leading to the issue.

The fix should be straightforward: simply remove the goroutine.
  • Loading branch information
alepane21 authored Jan 29, 2025
1 parent 3cbb4b5 commit b7e96dd
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions v2/pkg/engine/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,35 +426,33 @@ func (r *Resolver) handleHeartbeat(data []byte) {
continue
}

go func() {
if r.options.Debug {
fmt.Printf("resolver:heartbeat:subscription:%d\n", s.id.SubscriptionID)
}
if r.options.Debug {
fmt.Printf("resolver:heartbeat:subscription:%d\n", s.id.SubscriptionID)
}

s.mux.Lock()
if _, err := s.writer.Write(data); err != nil {
if errors.Is(err, context.Canceled) {
// client disconnected
s.mux.Unlock()
_ = r.AsyncUnsubscribeSubscription(s.id)
return
}
r.asyncErrorWriter.WriteError(c, err, nil, s.writer)
}
err := s.writer.Flush()
s.mux.Unlock()
if err != nil {
s.mux.Lock()
if _, err := s.writer.Write(data); err != nil {
if errors.Is(err, context.Canceled) {
// client disconnected
s.mux.Unlock()
_ = r.AsyncUnsubscribeSubscription(s.id)
return
}
if r.options.Debug {
fmt.Printf("resolver:heartbeat:subscription:flushed:%d\n", s.id.SubscriptionID)
}
if r.reporter != nil {
r.reporter.SubscriptionUpdateSent()
}
}()
r.asyncErrorWriter.WriteError(c, err, nil, s.writer)
}
err := s.writer.Flush()
s.mux.Unlock()
if err != nil {
// client disconnected
_ = r.AsyncUnsubscribeSubscription(s.id)
return
}
if r.options.Debug {
fmt.Printf("resolver:heartbeat:subscription:flushed:%d\n", s.id.SubscriptionID)
}
if r.reporter != nil {
r.reporter.SubscriptionUpdateSent()
}
}
}

Expand Down

0 comments on commit b7e96dd

Please sign in to comment.