Skip to content

Conversation

@sreenivasivbieb
Copy link

Description

Fixes data race in Kafka Subscribe method where concurrent access to k.reader map could cause race conditions.

Changes

  • Fixed data race by storing reader reference in local variable before unlocking mutex
  • Added nil check for mutex to prevent panic

Closes

Closes #2957

- Fixed data race in Subscribe method by using local variable for reader
- Added proper nil check for mutex to prevent panic
- Closes gofr-dev#2957
Copilot AI review requested due to automatic review settings February 5, 2026 12:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a data race condition in the Kafka Subscribe method where the reader map was accessed outside of mutex protection. The fix moves the reader reference assignment inside the critical section before unlocking the mutex, as requested in issue #2957.

Changes:

  • Moved reader = k.reader[topic] assignment inside the mutex lock (before k.mu.Unlock()) to prevent concurrent access issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coolwednesday
Copy link
Member

@sreenivasivbieb, Please fix the review comments by copilot.

@sreenivasivbieb
Copy link
Author

@coolwednesday i have implemented all the copilot changes and i even tested all test cases were passed, can u merge this pr with main branch

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.

Data Race in Kafka

2 participants