mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #1369] [Bug] Segfault/LogicError in SocketHandShakePlugin during high-concurrency RDMA transfers #441
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#441
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?
Originally created by @herrluk on GitHub (Jan 13, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/1369
Originally assigned to: @alogfans on GitHub.
Description
Component: Mooncake Transfer Engine (Python binding via
mooncake.engine.TransferEngine)When running high-concurrency RDMA transfers (e.g., 32+ concurrent recv operations across multiple machines), the Transfer Engine crashes with either a segmentation fault or a
Json::LogicErrorin the SocketHandShake daemon thread.Error Messages
Error 1: Segmentation Fault
dmesg output:
GDB backtrace:
Error 2: Json::LogicError
Environment
Use Case: Distributed Data Exchange with High-Concurrency RDMA
We are running a distributed workload where multiple processes across machines exchange data using Mooncake Transfer Engine.
Cluster Configuration
Data Flow
Reproduction Steps
Deploy a 32-node cluster with RDMA connectivity
Send phase: Each machine runs 2 processes, each creates 32 TransferEngine instances:
Receive phase: After sends complete, each machine runs 1 process with 32 TransferEngine instances doing concurrent recv:
The crash occurs sporadically during Phase 2, when multiple RDMA connections are being established simultaneously across the cluster (N-to-N handshake pattern)
Analysis
Both errors occur in
SocketHandShakePlugin::startDaemonwhen processing peer metadata:encodeSegmentDesc()encodes aSegmentDescstructure to JSONJson::Valuefrom a string field inSegmentDesc:This suggests a memory corruption issue in
SegmentDesc, possibly due to:SegmentDescstructureWorkaround
Reducing concurrency mitigates the issue:
Expected Behavior
The Transfer Engine should handle high-concurrency RDMA connections without crashing.
@staryxchen commented on GitHub (Jan 14, 2026):
@herrluk Please verify whether #1373 resolves the issue.
@herrluk commented on GitHub (Jan 19, 2026):
@staryxchen Thanks for your PR #1373! I tested it and it successfully fixed the original race condition crash.
Original crash scenario:
corrupted size vs. prev_size(glibc heap corruption detected)SocketHandShakePlugin::startDaemon→receivePeerMetadata→free()when releasingshared_ptr<SegmentDesc>segment_id_to_desc_map_corrupted the heap metadataHowever, as you mentioned in the PR description, I also encountered the deadlock issue in P2P metadata exchange scenarios - the
openSegmentoperation would hang indefinitely when trying to connect to a peer.After analyzing the code, I found a solution that avoids the deadlock while maintaining thread safety:
Key Insight
The deadlock occurs because
getSegmentDesc()tries to acquiresegment_lock_while its callers (getSegmentDescByName,syncSegmentCache,getSegmentID) already hold the write lock.My Fix
receivePeerMetadata(): UsegetLocalSegmentDesc()(with read lock) - this function is called fromstartDaemoncallback thread which does NOT hold any lock.getSegmentDesc(): Do NOT acquire lock again - its callers already hold the write lock. Direct map access is safe in this context.This approach follows the same "read-release-operate" pattern you described, but with the awareness that different call paths have different locking contexts.
The fix is working well in my high-concurrency tests (~2048 concurrent sends, ~1024 concurrent receives).
@staryxchen commented on GitHub (Jan 19, 2026):
Does the latest commit also have deadlock issues? If so, you can push your fix to PR #1373 , thank you!