There's a race on macOS when sending socket fd with sendmsg. The fd may get broken if it's closed before recvmsg is called.
I'm attaching a small program [test.c](/uploads/145cb273e664b8e0c433d016af0c1da1/test.c) that shows the issue outside of wine. The problem is easy to reproduce on macOS Sonoma and Monterey by running:
```
# gcc test.c
# ./a.out
```
It outputs "got fd in broken state" and quits after detecting fd in broken state.
It can also be reproduced in wine by starting new process and waiting until it finishes in a loop until wineserver crashes (usually it takes \~20 minutes to reproduce the crash this way).
There's similar code in server/thread.c:create_thread() but it's not affected by the bug because pipe fds are used.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5291