Skip to content

Make Process#wait asynchronous on Windows#13908

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:bug/windows-process-run-async
Oct 28, 2023
Merged

Make Process#wait asynchronous on Windows#13908
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:bug/windows-process-run-async

Conversation

@HertzDevil
Copy link
Contributor

Fixes #13492.

Every Crystal::System::Process now carries a Win32 job object that holds the process handle (but not its child processes). The job object then indicates process termination via an IOCP message, which Crystal's event loop already employs. Note that those messages have their own format and do not have a real LibC::OVERLAPPED.

This also effectively makes the playground work on Windows.

Does not affect #13425.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:concurrency platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system labels Oct 26, 2023

# at the moment only `::Process#wait` uses a non-nil completion key; all
# I/O operations, including socket ones, do not set this field
case completion_key = Pointer(Void).new(entry.lpCompletionKey).as(CompletionKey?)
Copy link
Member

Choose a reason for hiding this comment

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

I suppose it's probably okay to leverage the fact that unions of a reference type and Nil are represented as a simple pointer where the null pointe rexpresses a nil value. But it feels just a tiny bit iffy.
Feel free to ignore this comment, or refactor for a more explicit null pointer check if you think it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is the same assumption in Atomic and Box. Perhaps these special casts can be placed under something like Crystal::ABI later

@straight-shoota straight-shoota added this to the 1.11.0 milestone Oct 27, 2023
@straight-shoota straight-shoota merged commit 26819e3 into crystal-lang:master Oct 28, 2023
@HertzDevil HertzDevil deleted the bug/windows-process-run-async branch October 28, 2023 11:00
Blacksmoke16 pushed a commit to Blacksmoke16/crystal that referenced this pull request Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:concurrency topic:stdlib:system

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

WebSocket in child process gets stuck on Windows

2 participants