Skip to content

fix: resolve data race, hardcoded exchange, and channel churn#6

Merged
jamesdube merged 1 commit intomainfrom
fix/connection-and-emitter
Feb 25, 2026
Merged

fix: resolve data race, hardcoded exchange, and channel churn#6
jamesdube merged 1 commit intomainfrom
fix/connection-and-emitter

Conversation

@jamesdube
Copy link
Owner

Summary

  • Consumer data race: listenOnce() accessed connManager.conn directly without mutex protection (line 216). During reconnection, the reconnect() goroutine sets conn = nil under lock, causing a nil pointer panic. Fixed by using GetConnection() which acquires RLock.
  • Hardcoded exchange in emitter: setup() declared "logs_topic" exchange regardless of what exchange name is passed to Publish(). Removed — exchange declaration now happens in Publish() where the actual name is known.
  • Channel-per-publish churn: Publish() opened and closed a new AMQP channel on every call, causing unnecessary overhead under load. Replaced with a persistent channel (mutex-protected) that auto-recreates on failure. Exchange declarations are cached per channel lifetime.

Test plan

  • go build ./... compiles
  • go test ./... passes (lib/event tests)
  • Verified consumer uses mutex-protected GetConnection() for NotifyClose
  • Verified emitter reuses channel across publishes and resets on error

🤖 Generated with Claude Code

…t package

- Consumer: use GetConnection() instead of direct connManager.conn access
  in listenOnce() to prevent data race during reconnection
- Emitter: remove hardcoded "logs_topic" exchange declaration from setup();
  exchanges are now declared per-Publish() call where the name is known
- Emitter: reuse a persistent AMQP channel instead of opening/closing one
  per Publish() call; channel auto-recreates on failure with mutex protection
- Remove unused getExchangeName() helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jamesdube jamesdube merged commit ee0ea9f into main Feb 25, 2026
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.

1 participant