Repository navigation
fix: the access to consumer.consumers might not be thread safe - #1494
Conversation
|
I still noticed a few other direct accesses to
Was the intention here to only fix the msgID-based paths, or is there a reason not to update these remaining access sites in the same PR as well? |
|
@crossoverJie Good finding! Let me try a better approach, maybe we need to wrap a thread-safe list |
8f96f83 to
ba0903e
Compare
|
@crossoverJie Now I replaced the trivial slice with an |
|
I've reverted to the previous lock-based design and added comments for the issue here. PTAL again @mattisonchao |
|
The failed blue-green migration is not caused by this PR. Based on my analysis, the test failure is NOT caused by the commits since master. Here's why: Changes since master: Test failure root cause:
This is a pre-existing race condition in the reconnection logic — the consumer doesn't properly handle the case where a Subscribe request reaches the broker but the response doesn't reach the client. |
c.consumerscan be updated byinternalTopicSubscribeToPartitions, so we must accessc.consumerswhen holding a lock. However, many code places don't follow the implicit requirement, so nil pointer dereference could happen.This PR replaces the combination of c.checkMsgIDPartition(msgID) and c.consumers[msgID] with a wrapped method findPartitionConsumer, which retrieves the consumer with lock held. Specifically, for Seek, add an unsafe version (i.e. no lock acquired) because the lock has been acquired to check if len(c.consumers) > 1 before.
For other places that access
c.consumers(all are range for loops), ensure lock is acquired. The exceptional case is thehasNextmethod, we have to iterate over a snapshot, otherwise,c.Unlock()must be called afterwg.Wait(), which is impossible