# Fix git hang caused by accidental inheritance of stdin FD \(\#57572\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/2e2086046168d0c57142cfb5f1ff458c43cb8b14)

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

Visibility: public

Requested revision: 2e2086046168d0c57142cfb5f1ff458c43cb8b14

Requested commit: 2e2086046168d0c57142cfb5f1ff458c43cb8b14

Commit: 2e2086046168d0c57142cfb5f1ff458c43cb8b14

Tree: 74a9dd35c7251d4dcf5f544e9d7954eed751ddfb

Author: Max Brunsfeld

Committer: GitHub

## Message

```
Fix git hang caused by accidental inheritance of stdin FD (#57572)

When restarting Zed, I hit a bug where all Git operations were hung. I
realized that there was a hanging git process running `git cat-file
--batch-check=%(objectname)`. The process was waiting on stdin. This was
surprising, because [the
code](https://github.com/zed-industries/zed/blob/e2bbdb19b6da2ee157ca1d36100acde2134a1663/crates/git/src/repository.rs#L1665-L1709)
that spawns this process explicitly closes the pipe that is attached to
the process's stdin after writing a list of ref names.

Using Claude, I found that this could be caused by that pipe file
descriptor being cloned due to file descriptor inheritance when another
child process is `exec`'d while that stdin pipe is open. The fix is to
enhance our Darwin process spawning layer to set the close-on-exec flag
for the pipe file descriptors, so that they are not inherited by child
processes spawned using code paths that don't set
`POSIX_SPAWN_CLOEXEC_DEFAULT`.

Release Notes:

- Fixed a bug on macOS where Git operations could be blocked depending
on the timing of spawning child processes.
```

## Parents

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

[Source at this commit](https://git.cafe/gitcafe/zed/tree/2e2086046168d0c57142cfb5f1ff458c43cb8b14?format=markdown)
