Skip to content

fix: replace concorekill.bat single-PID overwrite with safe PID registry (#391)#489

Open
GaneshPatil7517 wants to merge 2 commits intoControlCore-Project:devfrom
GaneshPatil7517:fix/concorekill-pid-registry-v2
Open

fix: replace concorekill.bat single-PID overwrite with safe PID registry (#391)#489
GaneshPatil7517 wants to merge 2 commits intoControlCore-Project:devfrom
GaneshPatil7517:fix/concorekill-pid-registry-v2

Conversation

@GaneshPatil7517
Copy link

@GaneshPatil7517 GaneshPatil7517 commented Mar 4, 2026

Problem

On Windows, concore.py overwrote concorekill.bat at import time with a single
hardcoded PID. When multiple nodes launched simultaneously, each overwrote the file
only the last node's PID survived. Stale PIDs from crashed studies could also kill
unrelated processes.

Solution

Replace the 3-line overwrite block with an append-based PID registry:

  • _register_pid() - appends current PID to concorekill_pids.txt (append mode)
  • _cleanup_pid() - removes current PID on exit with msvcrt file locking
  • _write_kill_script() - generates concorekill.bat that validates each PID
    via tasklist before issuing taskkill

Users still run concorekill.bat as before - no workflow change.

Changes

  • concore.py: replaced lines 24–30 (the if hasattr(sys, 'getwindowsversion') block)
  • tests/test_concore.py: added TestPidRegistry class (9 tests) at end of file

No formatting changes, no unrelated edits.

Closes #391

…try (ControlCore-Project#391)

On Windows, concore.py overwrote concorekill.bat at import time with a
single PID, creating race conditions when multiple nodes launched
simultaneously and leaving stale PIDs after crashes.

Replace with append-based PID registry (concorekill_pids.txt):
- _register_pid(): appends current PID (append mode, no overwrite)
- _cleanup_pid(): removes current PID on exit with file locking
- _write_kill_script(): generates concorekill.bat that validates each
  PID via tasklist before issuing taskkill

Users still run concorekill.bat as before (backward compatible).
Copilot AI review requested due to automatic review settings March 4, 2026 12:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Windows race conditions and stale-PID hazards in concorekill.bat by replacing the single-PID overwrite behavior with a shared PID registry and a generated kill script that validates PIDs before terminating processes.

Changes:

  • Add a PID registry (concorekill_pids.txt) plus _register_pid(), _cleanup_pid(), and _write_kill_script() to manage multi-node termination on Windows.
  • Generate concorekill.bat to iterate over registered PIDs and validate each PID before attempting taskkill.
  • Add a TestPidRegistry test suite covering PID registry and script generation behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
concore.py Implements PID registry + cleanup + generated Windows kill script; hooks cleanup via atexit.
tests/test_concore.py Adds tests for PID registry creation/appending, cleanup semantics, and Windows import-time registration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…lock range with finally unlock, absolute paths

- Kill script uses wmic+concore instead of tasklist+python for precise PID validation
- _register_pid() now acquires file lock (same as _cleanup_pid)
- Lock range changed from 1 byte to 0x7FFFFFFF with LK_UNLCK in finally block
- _PID_REGISTRY_FILE and _KILL_SCRIPT_FILE use os.path.abspath at module init
- Tests updated: monkeypatch module-level paths to temp_dir, assert wmic/concore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants