[GH-ISSUE #446] [TransferEngine] Incorrect Error Handling in TransferEngine::allocateBatchID #154

Closed
opened 2026-10-29 21:10:14 +00:00 by bsakaguchi · 5 comments
Owner

Originally created by @chenhao-ye on GitHub (Jun 3, 2025).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/446

According to the document, BatchID TransferEngine::allocateBatchID(size_t batch_size) is expected to return a negative value (e.g., ERR_MEMORY) to indicate the failure. However, BatchID is unsigned (uint64_t) and actually carries a pointer to BatchDesc, so there is no way to indicate failure. In the case of failure, an error code is cast into a BatchDesc pointer and dereferenced, which can cause a segfault.

One potential fix is to avoid using a pointer as BatchID, but manage all allocated BatchDesc in a vector/map and return the index/key inside the vector/map as BatchID. This also eases the cleaning on TransferEngine destructor, which can track which batches have not been freed yet and manually do it.

Originally created by @chenhao-ye on GitHub (Jun 3, 2025). Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/446 According to the document, `BatchID TransferEngine::allocateBatchID(size_t batch_size)` is expected to return a negative value (e.g., `ERR_MEMORY`) to indicate the failure. However, `BatchID` is unsigned (`uint64_t`) and actually carries a pointer to `BatchDesc`, so there is no way to indicate failure. In the case of failure, an error code is cast into a BatchDesc pointer and dereferenced, which can cause a segfault. One potential fix is to avoid using a pointer as `BatchID`, but manage all allocated `BatchDesc` in a vector/map and return the index/key inside the vector/map as `BatchID`. This also eases the cleaning on `TransferEngine` destructor, which can track which batches have not been freed yet and manually do it.
bsakaguchi 2026-10-29 21:10:14 +00:00
Author
Owner

@alogfans commented on GitHub (Jun 12, 2025):

Currently we require the user to check the validity of returned batched id before using it. In our next version we will change the API to fix this problem (i.e. return both status and batch_id).

<!-- gh-comment-id:2964822825 --> @alogfans commented on GitHub (Jun 12, 2025): Currently we require the user to check the validity of returned batched id before using it. In our next version we will change the API to fix this problem (i.e. return both `status` and `batch_id`).
Author
Owner

@chenhao-ye commented on GitHub (Jun 12, 2025):

What would be the recommended way to check the validity of the batch id? Since it is unsigned, it will never be negative.

<!-- gh-comment-id:2964835950 --> @chenhao-ye commented on GitHub (Jun 12, 2025): What would be the recommended way to check the validity of the batch id? Since it is unsigned, it will never be negative.
Author
Owner

@alogfans commented on GitHub (Jun 17, 2025):

We have updated code, so that the batch id is guaranteed positive. The only error in BatchID allocation is out-of-memory.

<!-- gh-comment-id:2978712944 --> @alogfans commented on GitHub (Jun 17, 2025): We have updated code, so that the batch id is guaranteed positive. The only error in `BatchID` allocation is out-of-memory.
Author
Owner

@github-actions[bot] commented on GitHub (Jul 8, 2026):

This issue has had no activity for 90 days and will be closed in 7 days if there is no further activity. Please comment or react if it should stay open.

<!-- gh-comment-id:4911298329 --> @github-actions[bot] commented on GitHub (Jul 8, 2026): This issue has had no activity for 90 days and will be closed in 7 days if there is no further activity. Please comment or react if it should stay open.
Author
Owner

@github-actions[bot] commented on GitHub (Jul 16, 2026):

Closing due to 3 months of inactivity. If this is still relevant, please comment and we can reopen.

<!-- gh-comment-id:4988039714 --> @github-actions[bot] commented on GitHub (Jul 16, 2026): Closing due to 3 months of inactivity. If this is still relevant, please comment and we can reopen.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/Mooncake#154
No description provided.