# std.process.Child: add \`waitForSpawn\` · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/048e85f27e805f51c214e8e87e91a367a2873328)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 048e85f27e805f51c214e8e87e91a367a2873328

Requested commit: 048e85f27e805f51c214e8e87e91a367a2873328

Commit: 048e85f27e805f51c214e8e87e91a367a2873328

Tree: 9c159bc7888a9b3d758aa0c4ec6145f773354165

Author: mlugg

Committer: mlugg

## Message

```
std.process.Child: add `waitForSpawn`

`std.Build.Step.Run` makes the very reasonable assumption that
`error.InvalidExe` will be reported on `spawn` if it will happen.
However, this property does not currently hold on POSIX targets. This
is, through a slightly convoluted series of events, partially
responsible for the sporadic `BrokenPipe` errors we've been seeing more
and more in CI runs.

Making `spawn` wait for the child to exec in the POSIX path introduces
a block of up to 400us. So, instead of doing that, we add a new API for
this particular case: `waitForSpawn`. This function is a nop on Windows,
but on POSIX it blocks until the child successfully (or otherwise) calls
`execvpe`, and reports the error if necessary. `std.Build.Step.Run`
calls this function, so that it can get `error.InvalidExe` when it wants
it.

I'm not convinced that this API is optimal. However, I think this entire
API needs to be either heavily refactored or straight-up redesigned
(related: #22504), so I'm not too worried about hitting the perfect API:
I'd rather just fix this bug for now, and figure out the long-term goal
a bit later.

```

## Parents

- [b8e568504e1dca38273a5845ac20d056cd7db5bb](https://git.cafe/gitcafe/zig/commit/b8e568504e1dca38273a5845ac20d056cd7db5bb?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/048e85f27e805f51c214e8e87e91a367a2873328?format=markdown)
