error in the thread handle check and thread synchronization #23897

Closed
opened 2026-01-31 08:55:27 +00:00 by claunia · 1 comment
Owner

Originally created by @ayush45-ui on GitHub (Dec 22, 2025).

Windows Terminal version

No response

Windows build number

No response

Other Software

No response

Steps to reproduce

Add thread creation error checking - Verifies _beginthread() didn't return -1
Fixe process handle cleanup - Only closes handles if CreateProcess succeeded
Improve thread synchronization - Closes output pipe to signal EOF, then waits for listener thread to complete

Expected Behavior

No response

Actual Behavior

Thread Handle Check--
cppHANDLE hPipeListenerThread{ reinterpret_cast(_beginthread(PipeListener, 0, hPipeIn)) };
_beginthread() returns (uintptr_t)-1 on error, but there's no error checking before proceeding.
Process Handle Cleanup--
The code closes piClient.hThread and piClient.hProcess even if CreateProcess failed, which could close invalid handles.
Thread Synchronization--
Using Sleep(500) is unreliable for thread synchronization. The listener thread may still be running when cleanup begins.

Originally created by @ayush45-ui on GitHub (Dec 22, 2025). ### Windows Terminal version _No response_ ### Windows build number _No response_ ### Other Software _No response_ ### Steps to reproduce Add thread creation error checking - Verifies _beginthread() didn't return -1 Fixe process handle cleanup - Only closes handles if CreateProcess succeeded Improve thread synchronization - Closes output pipe to signal EOF, then waits for listener thread to complete ### Expected Behavior _No response_ ### Actual Behavior Thread Handle Check-- cppHANDLE hPipeListenerThread{ reinterpret_cast<HANDLE>(_beginthread(PipeListener, 0, hPipeIn)) }; _beginthread() returns (uintptr_t)-1 on error, but there's no error checking before proceeding. Process Handle Cleanup-- The code closes piClient.hThread and piClient.hProcess even if CreateProcess failed, which could close invalid handles. Thread Synchronization-- Using Sleep(500) is unreliable for thread synchronization. The listener thread may still be running when cleanup begins.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 08:55:27 +00:00
Author
Owner

@lhecker commented on GitHub (Jan 5, 2026):

I'll close this issue for now. If you make any such changes, you can just send a PR without further explanation. Your previous PR is not in a state that it can be merged, however.

@lhecker commented on GitHub (Jan 5, 2026): I'll close this issue for now. If you make any such changes, you can just send a PR without further explanation. Your previous PR is not in a state that it can be merged, however.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23897