Skip to content

Disable go-metrics for Kafka to prevent memory leak#53

Merged
oskarszoon merged 4 commits into
bsv-blockchain:mainfrom
oskarszoon:bugfix/sarama-memory-leak
Oct 24, 2025
Merged

Disable go-metrics for Kafka to prevent memory leak#53
oskarszoon merged 4 commits into
bsv-blockchain:mainfrom
oskarszoon:bugfix/sarama-memory-leak

Conversation

@oskarszoon

Copy link
Copy Markdown
Contributor

Followup to #51

image

@github-actions

github-actions Bot commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Status: Complete


This PR improves the memory leak fix from #51 by using a global solution instead of per-client configuration. The approach is sound and follows best practices for the Sarama library.

Strengths:

  • Uses metrics.UseNilMetrics = true globally via init() - this is the recommended approach per the Sarama maintainers
  • Consolidates the fix to a single location rather than repeating it across multiple client instantiations
  • Properly placed in kafka_producer_async.go which is imported by all other Kafka client code

Considerations:

  • The test files in test/longtest/util/kafka/simple_test.go and test/chaos/scenario_02_kafka_broker_failure_test.go also create Sarama configs directly but should be covered by the global setting
  • The init() function will execute when the package is imported, ensuring the setting applies before any Sarama clients are created

No issues found. The implementation correctly addresses the memory leak using the globally recommended solution.

@sonarqubecloud

Copy link
Copy Markdown

@oskarszoon oskarszoon merged commit a42a27c into bsv-blockchain:main Oct 24, 2025
10 of 11 checks passed
@oskarszoon oskarszoon self-assigned this Oct 24, 2025
torrejonv pushed a commit to torrejonv/teranode that referenced this pull request Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants