Implement SafeProcessHandle.WaitForExit* methods#127022
Conversation
- Add WaitForExit, TryWaitForExit, WaitForExitOrKillOnTimeout, WaitForExitAsync, WaitForExitOrKillOnCancellationAsync to SafeProcessHandle - Windows: uses ProcessWaitHandle + GetExitCodeProcess - Unix: integrates with ProcessWaitState for reaping coordination - Native: WaitPidExitedNoHang now returns terminating signal info - ProcessWaitState: tracks terminating signal for ProcessExitStatus - Ref assembly: updated with new API surface - Tests: added comprehensive WaitForExit* tests Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3540beba-26c4-4014-b276-d6fa244eda82 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
…e ToTimeoutMilliseconds to ProcessUtils, remove KillCore, fix platform attributes, update native PAL - ProcessWaitState: store ProcessExitStatus? instead of separate _exitCode/_terminatingSignal - Native PAL: use TryConvertSignalCodeToPosixSignal for proper PosixSignal mapping - Move ToTimeoutMilliseconds to ProcessUtils.cs, reuse from Process and SafeProcessHandle - Remove separate KillCore methods on both platforms; use SignalCore on Unix, TerminateProcessCore on Windows - Remove platform attributes from WaitForExit, TryWaitForExit, WaitForExitAsync (non-killing methods) - Fix CreateExitStatus canceled logic: canceled && signal is not null - Update Process.Unix.cs to consume ProcessExitStatus? from GetExited Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1a601c8b-3c5f-4596-9b8f-5e11188e35ae Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ssCore Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1a601c8b-3c5f-4596-9b8f-5e11188e35ae Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
… pragma, simplify Unix async via ProcessWaitState.WaitForExitAsync, add PlatformNotSupportedException checks, rename wasKilled to signalWasSent, add Debug.Assert, update ProcessHandlesTests.Windows.cs Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/603f063f-b34a-42f8-ab6b-e1aa2df62675 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
- there is no need to start suspended process anymore, as we can wait on the handle to exit directly - revert changes I did not like
🤖 Copilot Code Review — PR #127022Note This review was generated by GitHub Copilot using the code-review skill. Findings were cross-validated across multiple model families (Gemini 2.5 Pro, GPT-5.3-Codex). Holistic AssessmentMotivation: The PR implements the approved Approach: The implementation correctly follows the platform delegation pattern — shared async logic in Summary: ✅ LGTM. The core implementation is correct and well-tested. The API surface matches the approved design. The async patterns are sound, resource cleanup is proper, and all previous reviewer feedback has been addressed. The findings below are advisory observations, not merge blockers. Detailed Findings✅ API Surface — Matches approved shape for WaitForExit methodsThe 5 new methods ( ✅ Async patterns — Correct use of RegisterWaitForSingleObject + TCS
✅ Wait state holder ownership — Clean ref-countingEach ✅ Non-child process guard — PlatformNotSupportedException is correct
✅ Native PAL — Signal propagation is correct
✅ Test coverage — ComprehensiveTests cover: normal exit, timeout, kill-on-timeout, async cancellation, invalid handles, non-child processes, signal reporting ( 💡 Incorrect comment in
|
🤖 Copilot Code Review — PR #127022Note This review was generated by Copilot and should be treated as AI-generated feedback. Holistic AssessmentMotivation: This PR implements Approach: The implementation reuses existing infrastructure — Summary: Detailed Findings✅ Ref-Count Management — Correctly implementedThe
The ✅ Windows Implementation — Clean and correctThe Windows ✅ Async Pattern — Well-structured
The cancellation callback in ✅ Native PAL Change — Correct signal mapping
✅ Test Coverage — ComprehensiveTests cover happy paths (normal exit), timeouts, cancellation, invalid handles, non-child processes (Unix vs Windows behavior divergence), signal reporting, and post-kill waits. Good use of
|
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/233caaed-255c-439e-88f8-2add4a7073d5 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…his keyword Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/0d008eb6-d008-409c-af71-0f12f92cf3b8 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…lder is null, matching GetWaitState behavior Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/39918226-b319-44db-bc83-21f04f48d3b9 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
🤖 Copilot Code Review — PR #127022Note This review was generated by GitHub Copilot using the code-review skill. Findings were cross-validated across multiple model families (Gemini 2.5 Pro, GPT-5.3-Codex). Holistic AssessmentMotivation: The PR implements the approved Approach: The implementation correctly follows the platform delegation pattern — shared async logic in Summary: ✅ LGTM. The core implementation is correct and well-tested. The API surface matches the approved design. The async patterns are sound, resource cleanup is proper, and all previous reviewer feedback has been addressed. The findings below are advisory observations, not merge blockers. Detailed Findings✅ API Surface — Matches approved shape for WaitForExit methodsThe 5 new methods match the approved API from the API review comment. Parameter names match between ref and src. Platform attributes are correctly applied — only methods involving process termination have ✅ Async patterns — Correct use of RegisterWaitForSingleObject + TCS
✅ Ref-counting — Thread-safe holder pattern
✅ Exception consistency — ProcessId and GetWaitState alignedBoth ✅ Native PAL — Signal propagation correct
💡
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/ba-g browser failures are unrelated |
Implements the approved
SafeProcessHandle.WaitForExit*API surface from #123380.Description
Adds 5 new public methods to
SafeProcessHandle:WaitForExit,TryWaitForExit,WaitForExitOrKillOnTimeout,WaitForExitAsync, andWaitForExitOrKillOnCancellationAsync.Key changes
SafeProcessHandle.csusingRegisterWaitForSingleObject+TaskCompletionSourceProcessWaitHandle+GetExitCodeProcessfor synchronous wait and exit code retrievalProcessWaitStatefor reaping coordination;ProcessIdproperty moved to platform-specific file and reads from_waitStateHolder._state._processIdWaitPidExitedNoHangnow returns terminating signal info viaTryConvertSignalCodeToPosixSignalProcessExitStatus?instead of separate_exitCode/_terminatingSignalfields; addedHolder.IncrementRefCount()for ref-counted ownership sharing betweenProcessandSafeProcessHandleGetProcessHandle()andStartCoreuseIncrementRefCount()pattern for proper wait state holder ownershipProcessIdandGetWaitState()now throwInvalidOperationExceptionwhen_waitStateHolderis null (previouslyProcessIdthrewPlatformNotSupportedException);GetWaitState()throwsPlatformNotSupportedExceptionfor non-child processes on UnixWaitForExit*tests including sync/async theories, signal reporting, timeout/kill behavior, non-child process handling, andProcess.SafeHandleinterop