Files
PowerToys/src/common/UnitTests-CommonUtils
Gordon Lam ed7595f3a7 Harden IPC pipe ownership and shutdown lifecycle (#48902)
## Summary of the Pull Request

The two-way named-pipe IPC server (`TwoWayPipeMessageIPC`, shared by the
runner, Settings, and Quick Access host) created every pipe instance
without `FILE_FLAG_FIRST_PIPE_INSTANCE`. If a pipe with the same name
already existed — for example a leftover instance from a previous run or
another process — `CreateNamedPipe` would quietly create an *additional*
instance and share the name instead of owning it.

This makes `start_named_pipe_server` create the **first** instance with
`FILE_FLAG_FIRST_PIPE_INSTANCE`, so `CreateNamedPipe` fails fast on a
name collision and the server is the authoritative owner of its pipe
name.

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
(N/A — no user-facing strings)
- [x] **Dev docs:** Added/updated (N/A)
- [x] **New binaries:** Added on the required places (N/A — no new
binaries)

## Detailed Description of the Pull Request / Additional comments

- The flag is applied **only** to the first instance. Subsequent
instances continue to omit it, so the existing
`PIPE_UNLIMITED_INSTANCES` behavior is fully preserved.
- The change is contained to a single function in
`src/common/interop/two_way_pipe_message_ipc.cpp`. Public signatures and
the `PowerToys.Interop` ABI are unchanged, so the runner, Settings, and
Quick Access host all benefit without any code changes on their side.

## Validation Steps Performed

- The existing `Common.Interop.UnitTests` `TestSend` exercises the
modified first-instance code path (`Start()` →
`start_named_pipe_server`) and continues to pass — a full IPC round-trip
still works.
- Verified the updated `CreateNamedPipe` open-mode logic compiles
cleanly.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 49797c8c-784d-47e6-bc0f-53464eecec4b
2026-08-09 20:56:12 +08:00
..