Under PyPy, it seems that socket.fromfd in the superserver check can have strange side effects on sockets, possibly related to concurrency. Setting detach_process=True removes the issue and is therefore a workaround. I have narrowed it down to specifically socket.fromfd from there.
socket.fromfd
I haven't managed to have a small test case, I use python-daemon as the start of a set of multiprocess/multithread processes. The issue appears in multiple cases - in one, the file descriptor for the open log file gets "mixed up" with that for a Redis connection causing my logs to be sent to Redis over TCP instead. In others, the log ends up closed prematurely causing further log writes to fail with EBADF.
How this call causes these issues, or why it only occurs on PyPy, is unknown to me, and there may not be enough info here to fix anything at this time. Still, I thought it was worth reporting. The PR in the project where I encountered this has some strace samples.
PyPy version I saw this on:
Python 3.10.12 (af44d0b8114cb82c40a07bb9ee9c1ca8a1b3688c, Jun 16 2023, 10:41:03) [PyPy 7.3.12 with GCC 13.1.1 20230429] on linux
How this call causes these issues, or why it only occurs on PyPy, is unknown to me, and there may not be enough info here to fix anything at this time.
Thank you; if you can detail a reproducible way to see this behaviour, that will allow investigating this.
Metadata Update from @bignose: - Issue tagged with: more-info