[exporterhelper] queue_batch deadlocks on partition eviction when num_consumers is 1

Author: goingforstudying-ctrlCreated Oct 1, 2026Updated Oct 1, 2026

Component(s)

exporter/exporterhelper

What happened?

Split out of #16061 per @iblancasa's request for one ticket per problem. This ticket is only about the deadlock.

Describe the bug

With metadata_keys configured and num_consumers: 1, the worker pool can wedge permanently on the first LRU cache eviction.

multi_batcher.go registers an eviction callback that calls workerPool.execute(pb.shutdownInternal). The callback fires inside partitions.Add, so it runs synchronously from Consume while mb.lock is held. workerPool.execute takes its semaphore token in the caller and only hands it back in the spawned goroutine's defer. The shutdown goroutine then runs flushCurrentBatchOrRemovePartition, which calls flush, which calls workerPool.execute again. With a single worker that nested call waits on the token its own goroutine is already holding, so it blocks forever.

The failure is silent. Consume returns normally, but the pool is dead, and the collector keeps accepting telemetry it can never send.

Steps to reproduce

Same shape as TestMultiBatcher_CacheSizeEviction but with newWorkerPool(1) and CacheSize: 2. Two consumes create two partitions, a third consume evicts the first one, and any flush after that never returns.

The test suite already hints at this:

go
// Evicting a partition flushes it through the worker pool, which in turn needs
// a worker to send the pending batch, so more than one worker is required.

The requirement is known but right now it's only worked around in the test. Config.Validate doesn't reject num_consumers: 1 with metadata_keys.

What did you expect to see?

Evictions and flushes complete no matter how many workers are configured.

What did you see instead?

With num_consumers: 1, the exporter stops sending as soon as the first partition is evicted. Nothing is logged and Consume keeps returning success, so telemetry keeps piling into the queue and never leaves.

Collector version

v0.162.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04") Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

yaml
exporters:
  otlphttp:
    endpoint: http://localhost:4318
    sending_queue:
      num_consumers: 1
      batch:
        metadata_keys: [tenant]
        partition:
          cache_size: 2

Log output

bash

Additional context

I have a patch that moves the eviction dispatch out from under mb.lock and runs the final shutdown flush on the worker goroutine that is already executing shutdownInternal, instead of acquiring a second worker. Will open a PR shortly.

Source: open-telemetry/opentelemetry-collector