Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test TestSimpleSpanProcessorShutdownHonorsContextCancel #2290

Merged
merged 9 commits into from Oct 19, 2021
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Adds `otlptracegrpc.WithGRPCConn` and `otlpmetricgrpc.WithGRPCConn` for reusing existing gRPC connection. (#2002)
- Added a new `schema` module to help parse Schema Files in OTEP 0152 format. (#2267)

### Fixed

- 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

### Fixed
Expand Down
12 changes: 11 additions & 1 deletion sdk/trace/simple_span_processor.go
Expand Up @@ -91,7 +91,17 @@ func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error {
select {
case err = <-done:
case <-ctx.Done():
err = ctx.Err()
// It is possible for the exporter to have immediately shut down
// and the context to already be done. In that case this select
// statement will randomly choose a case. This could result in a
// different response for similar scenarios. Instead, double check
// if the exporter shut down at the same time and return that
// error if so.
if expErr, ok := <-done; ok {
err = expErr
} else {
err = ctx.Err()
}
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
}
})
return err
Expand Down
10 changes: 8 additions & 2 deletions sdk/trace/simple_span_processor_test.go
Expand Up @@ -40,9 +40,15 @@ func (t *testExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnl
return nil
}

func (t *testExporter) Shutdown(context.Context) error {
func (t *testExporter) Shutdown(ctx context.Context) error {
t.shutdown = true
return nil
select {
case <-ctx.Done():
// Ensure context deadline tests receive the expected error.
return ctx.Err()
default:
return nil
}
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
}

var _ sdktrace.SpanExporter = (*testExporter)(nil)
Expand Down