fix: honor explicit IPC names#379
Open
shipiyouniao wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Issue #378 by making KVCACHED_IPC_NAME an exact (sanitized) IPC namespace when explicitly set, avoiding any auto-suffixing/uniqueness probing that could cause later workers to join a different shared-memory namespace.
Changes:
- Update
_obtain_default_ipc_name()to immediately return the sanitized explicitKVCACHED_IPC_NAMEwithout probing/suffixing. - Add a unit test covering the explicit-name path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_ipc_name.py | Adds a regression test for treating an explicit IPC name as exact. |
| kvcached/utils.py | Removes uniqueness probing/suffixing when KVCACHED_IPC_NAME is explicitly set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+65
to
+69
| explicit = os.getenv("KVCACHED_IPC_NAME") | ||
| if explicit: | ||
| preferred = _sanitize_segment(explicit) | ||
|
|
||
| if not _ipc_segment_exists(preferred): | ||
| return preferred | ||
|
|
||
| base_candidate = f"{preferred}_{engine_tag}_{group_id}" | ||
| if not _ipc_segment_exists(base_candidate): | ||
| return base_candidate | ||
| # As a last resort, append a small numeric suffix until unique | ||
| for i in range(1, 100): | ||
| candidate = f"{base_candidate}_{i}" | ||
| if not _ipc_segment_exists(candidate): | ||
| return candidate | ||
| # If everything somehow exists, fall back to PID-specific name | ||
| return f"{base_candidate}_{os.getpid()}" | ||
| # An explicit IPC name is a contract between all processes in one | ||
| # serving instance. Do not auto-suffix it when the segment already | ||
| # exists: late-importing TP workers must still join the same namespace, |
Comment on lines
+14
to
+16
| monkeypatch.setenv("KVCACHED_IPC_NAME", "shared-instance-ipc") | ||
| monkeypatch.setattr(utils, "_ipc_segment_exists", lambda name: True) | ||
|
|
785b5c8 to
27f7aa9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #378.
Treat
KVCACHED_IPC_NAMEas an exact IPC namespace when it is explicitly set. The generated-name path still keeps the existing uniqueness probing.Why
The explicit env var is used as a process coordination contract. If kvcached auto-suffixes it after the segment already exists, later workers can join a different namespace than the process that created the segment.
Tests