Skip to content

Commit

Permalink
stanza: respect context in emittest.Sink (open-telemetry#32733)
Browse files Browse the repository at this point in the history
**Description:**

Respect context cancellation in emittest.Sink to prevent deadlock if the
emit callback is invoked during manager shutdown.

**Link to tracking Issue:** <Issue number if applicable>

Related to
open-telemetry#32391.
Increasing the poll interval in TestCopyTruncate to 5s reliably causes
the "timeout: expected: 2700, actual: ..." failure in the linked issue;
the test never terminates, and this blocks other tests from running.

**Testing:**

N/A, fixing test code

**Documentation:**

N/A
  • Loading branch information
axw authored and cparkins committed Jul 11, 2024
1 parent a909dd5 commit e207c97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/stanza/fileconsumer/internal/emittest/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ func NewSink(opts ...SinkOpt) *Sink {
return &Sink{
emitChan: emitChan,
timeout: cfg.timeout,
Callback: func(_ context.Context, token []byte, attrs map[string]any) error {
Callback: func(ctx context.Context, token []byte, attrs map[string]any) error {
copied := make([]byte, len(token))
copy(copied, token)
emitChan <- &Call{copied, attrs}
select {
case <-ctx.Done():
return ctx.Err()
case emitChan <- &Call{copied, attrs}:
}
return nil
},
}
Expand Down

0 comments on commit e207c97

Please sign in to comment.