You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-25 00:16:49 +02:00
Fix flaky test TestSimpleSpanProcessorShutdownHonorsContextCancel (#2290)
* Fix flaky test TestSimpleSpanProcessorShutdownHonorsContextCancel * Add changes to changelog * Prioritize return of exporter error * Update changelog description * Fix deadlock bug
This commit is contained in:
@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- `semconv.NetAttributesFromHTTPRequest()` correctly handles IPv6 addresses. (#2285)
|
- `semconv.NetAttributesFromHTTPRequest()` correctly handles IPv6 addresses. (#2285)
|
||||||
|
- The simple span processor shutdown method deterministically returns the exporter error status if it simultaneously finishes when the deadline is reached. (#2290, #2289)
|
||||||
|
|
||||||
## [1.0.1] - 2021-10-01
|
## [1.0.1] - 2021-10-01
|
||||||
|
|
||||||
|
@ -88,11 +88,25 @@ func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error {
|
|||||||
|
|
||||||
go shutdown()
|
go shutdown()
|
||||||
|
|
||||||
|
// Wait for the exporter to shut down or the deadline to expire.
|
||||||
select {
|
select {
|
||||||
case err = <-done:
|
case err = <-done:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
// It is possible for the exporter to have immediately shut down
|
||||||
|
// and the context to be done simultaneously. In that case this
|
||||||
|
// outer select statement will randomly choose a case. This will
|
||||||
|
// result in a different returned error for similar scenarios.
|
||||||
|
// Instead, double check if the exporter shut down at the same
|
||||||
|
// time and return that error if so. This will ensure consistency
|
||||||
|
// as well as ensure the caller knows the exporter shut down
|
||||||
|
// successfully (they can already determine if the deadline is
|
||||||
|
// expired given they passed the context).
|
||||||
|
select {
|
||||||
|
case err = <-done:
|
||||||
|
default:
|
||||||
err = ctx.Err()
|
err = ctx.Err()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,16 @@ func (t *testExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnl
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testExporter) Shutdown(context.Context) error {
|
func (t *testExporter) Shutdown(ctx context.Context) error {
|
||||||
t.shutdown = true
|
t.shutdown = true
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
// Ensure context deadline tests receive the expected error.
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var _ sdktrace.SpanExporter = (*testExporter)(nil)
|
var _ sdktrace.SpanExporter = (*testExporter)(nil)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user