1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-01 00:24:59 +02:00

otlptracegrpc: Shutdown returns context error (#3990)

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Robert Pająk
2023-04-13 16:55:24 +02:00
committed by GitHub
parent b24bcc1fc8
commit eb2b89f335

View File

@ -130,13 +130,16 @@ var errAlreadyStopped = errors.New("the client is already stopped")
// If the client has already stopped, an error will be returned describing // If the client has already stopped, an error will be returned describing
// this. // this.
func (c *client) Stop(ctx context.Context) error { func (c *client) Stop(ctx context.Context) error {
// Make sure to return context error if the context is done when calling this method.
err := ctx.Err()
// Acquire the c.tscMu lock within the ctx lifetime. // Acquire the c.tscMu lock within the ctx lifetime.
acquired := make(chan struct{}) acquired := make(chan struct{})
go func() { go func() {
c.tscMu.Lock() c.tscMu.Lock()
close(acquired) close(acquired)
}() }()
var err error
select { select {
case <-ctx.Done(): case <-ctx.Done():
// The Stop timeout is reached. Kill any remaining exports to force // The Stop timeout is reached. Kill any remaining exports to force