mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[PR #1373] [MERGED] [TE] Fix race condition in receivePeerMetadata and getSegmentDesc #2200
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#2200
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/Mooncake/pull/1373
Author: @staryxchen
Created: 1/14/2026
Status: ✅ Merged
Merged: 1/23/2026
Merged by: @alogfans
Base:
main← Head:fix-add-lock-for-local-segment-access📝 Commits (1)
901085frefactor(transfer_metadata): improve thread safety and reduce lock contention📊 Changes
1 file changed (+86 additions, -24 deletions)
View changed files
📝
mooncake-transfer-engine/src/transfer_metadata.cpp(+86 -24)📄 Description
Summary
This PR fixes a race condition in
TransferMetadata::receivePeerMetadataandTransferMetadata::getSegmentDescfunctions where concurrent access tosegment_id_to_desc_map_without proper locking could cause crashes under high concurrency scenarios.As reported in Issue #1369, when running with high RDMA concurrency (~2048 concurrent sends, ~1024 concurrent receives), the
SocketHandShakePlugincrashes during handshake processing with:Json::Value::Value(std::string const&)length too big for prefixingRoot Cause
The
receivePeerMetadataandgetSegmentDescfunctions accessedsegment_id_to_desc_map_[LOCAL_SEGMENT_ID]without holdingsegment_lock_, while other functions (addLocalMemoryBuffer,removeLocalMemoryBuffer) modify this map and theSegmentDesccontents under write lock protection. This creates a race condition where:receivePeerMetadatato handle handshake requestssegment_id_to_desc_map_[LOCAL_SEGMENT_ID]viaaddLocalMemoryBuffer/removeLocalMemoryBufferSolution
Added
RWSpinlock::ReadGuardprotection when accessingsegment_id_to_desc_map_in both affected functionsreceivePeerMetadataandgetSegmentDesc(in p2p handshake mode).Type of Change
How Has This Been Tested?
Reproduction
The race condition can be reproduced by creating a test that:
addLocalMemoryBuffer/removeLocalMemoryBufferto modifysegment_id_to_desc_map_[LOCAL_SEGMENT_ID]getSegmentDescByID(LOCAL_SEGMENT_ID)and access the returnedSegmentDescfields (especiallybuffersvector and string fields)Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.