Created attachment 206476 [details]
Reporduce the problem with file description corruption
Transferring file descriptors to another process without waiting confirmations leads to unexpected behavior: descriptor is successfully transferred but attempt to read from is reported as EOF (recv returns 0).
Attached example reproduces the problem (please build it with -pthread option).
If number of client threads is set to 1, then problem is not reproduced.
Another way to fix the problem is to wait confirmation about descriptor delivery and close socket only after it.
It is seems to be critical that socket should not be closed before confirmation of the transfer: if we wait confirmation but close socket before, then the problem is still persists.
The bug is reproduced at several versions of FreeBSD including 12.0-stable and also recent Mac-OS/X.
There was bug report with similar symptoms:
But looks likes r343784 is not fixing it.