Skip to content

fix(kafka/sarama_broker): drain async producer Successes/Errors channels (#72)#120

Merged
galt-tr merged 2 commits into
mainfrom
fix/issue-72-sarama-async-channels
May 1, 2026
Merged

fix(kafka/sarama_broker): drain async producer Successes/Errors channels (#72)#120
galt-tr merged 2 commits into
mainfrom
fix/issue-72-sarama-async-channels

Conversation

@galt-tr
Copy link
Copy Markdown
Contributor

@galt-tr galt-tr commented May 1, 2026

Summary

  • Spawned two drainer goroutines for the async producer's Successes() and Errors() channels in kafka/sarama_broker.go. Without them, the channels (capacity = ChannelBufferSize, default 256) filled and the producer blocked on Input() for the rest of the process lifetime.
  • Errors are logged via the broker's zap logger and counted via the existing arcade_kafka_produce_errors_total{topic} metric — no new metric was needed.
  • Close() now waits on a sync.WaitGroup so drainer goroutines exit cleanly before the broker reports closed.
  • Kept NewSaramaBroker(brokers, consumerGroup) signature unchanged. Added a sibling NewSaramaBrokerWithLogger for callers that want to inject a logger; the no-arg constructor falls back to zap.NewNop().
  • Added kafka/sarama_broker_test.go covering: success-channel drain (1024 messages, would deadlock without the fix), error-channel drain (512 failing messages), and Close() waiting on drainers.

Closes #72

Test plan

  • go build ./...
  • go vet ./...
  • go test ./kafka/... -race
  • golangci-lint run ./kafka/... (0 issues)
  • Full repo go test ./... -race passes
  • Reviewer to verify metric reuse (arcade_kafka_produce_errors_total) is acceptable rather than a separate ..._async_produce_errors_total

)

The async Sarama producer was configured with Return.Successes=true and
Return.Errors=true but no goroutine drained those channels, so they
filled up and the producer blocked indefinitely. Two drainer goroutines
now consume both channels for the producer's lifetime. Errors are
logged and counted via the existing arcade_kafka_produce_errors_total
metric. Closes F-014.
@galt-tr galt-tr requested a review from mrz1836 as a code owner May 1, 2026 19:02
@github-actions github-actions Bot added the size/L Large change (201–500 lines) label May 1, 2026
@github-actions github-actions Bot added the bug-P3 Lowest rated bug, affects nearly none or low-impact label May 1, 2026
@galt-tr galt-tr merged commit 01f41ee into main May 1, 2026
45 checks passed
@galt-tr galt-tr deleted the fix/issue-72-sarama-async-channels branch May 1, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-P3 Lowest rated bug, affects nearly none or low-impact size/L Large change (201–500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[F-014] async Sarama producer channels are enabled but never drained

2 participants