From 19877b1654652c25929e9b27c5256d997b786bd9 Mon Sep 17 00:00:00 2001 From: Danny Shemesh Date: Fri, 4 Oct 2024 10:48:57 +0300 Subject: [PATCH] Fix timer channel drain to avoid hanging in Go 1.23 (#5869) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix timer channel drain to avoid hanging in go1.23 w/ asynctimerchan=0 (https://github.com/open-telemetry/opentelemetry-go/issues/5868) --------- Co-authored-by: Robert PajÄ…k Co-authored-by: Damien Mathieu <42@dmathieu.com> --- CHANGELOG.md | 1 + sdk/trace/batch_span_processor.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb9991a59df..b52b4749f2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The race condition for multiple `FixedSize` exemplar reservoirs identified in #5814 is resolved. (#5819) - Fix log records duplication in case of heterogeneous resource attributes by correctly mapping each log record to it's resource and scope. (#5803) +- Fix timer channel drain to avoid hanging on Go 1.23. (#5868) diff --git a/sdk/trace/batch_span_processor.go b/sdk/trace/batch_span_processor.go index 1d399a75db2..4ce757dfd6b 100644 --- a/sdk/trace/batch_span_processor.go +++ b/sdk/trace/batch_span_processor.go @@ -316,7 +316,11 @@ func (bsp *batchSpanProcessor) processQueue() { bsp.batchMutex.Unlock() if shouldExport { if !bsp.timer.Stop() { - <-bsp.timer.C + // Handle both GODEBUG=asynctimerchan=[0|1] properly. + select { + case <-bsp.timer.C: + default: + } } if err := bsp.exportSpans(ctx); err != nil { otel.Handle(err)