Skip to content

process: unregister Windows wait before closing child handle - #8564

Merged
Darksonn merged 2 commits into
tokio-rs:tokio-1.51.xfrom
Darksonn:f14
Oct 2, 2026
Merged

Darksonn merged 2 commits into
tokio-rs:tokio-1.51.xfrom
Darksonn:f14

Conversation

@Darksonn

@Darksonn Darksonn commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

On Windows, tokio::process::imp::Child previously declared child: StdChild before waiting: Option<Waiting>. Because Rust drops struct fields in declaration order, dropping a Child with an active wait registration closed the underlying process handle in StdChild::drop before Waiting::drop called UnregisterWaitEx, violating the Win32 RegisterWaitForSingleObject contract.

Reorder the fields of Child so that waiting is dropped before child, ensuring UnregisterWaitEx completes before StdChild closes the process handle.

Fixes: #8563

On Windows, `tokio::process::imp::Child` previously declared `child:
StdChild` before `waiting: Option<Waiting>`. Because Rust drops struct
fields in declaration order, dropping a `Child` with an active wait
registration closed the underlying process handle in `StdChild::drop`
before `Waiting::drop` called `UnregisterWaitEx`, violating the Win32
`RegisterWaitForSingleObject` contract.

Reorder the fields of `Child` so that `waiting` is dropped before
`child`, ensuring `UnregisterWaitEx` completes before `StdChild` closes
the process handle.

Fixes: tokio-rs#8563
@Darksonn Darksonn added C-enhancement Category: A PR with an enhancement or bugfix. A-tokio Area: The main tokio crate M-process Module: tokio/process S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2026

@GlenDC GlenDC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix looks correct to me. Will this be forward-ported? master still has the old field order.

Comment thread tokio/src/process/windows.rs Resolved
Comment thread tokio/src/process/windows.rs Resolved
@Darksonn

Darksonn commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

Yes, forward port is part of our release process.

@Darksonn Darksonn removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 2, 2026

@ADD-SP ADD-SP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@Darksonn
Darksonn enabled auto-merge (squash) October 2, 2026 22:53
@Darksonn
Darksonn merged commit 9a47992 into tokio-rs:tokio-1.51.x Oct 2, 2026
86 checks passed
@Darksonn
Darksonn deleted the f14 branch October 3, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-process Module: tokio/process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants