2020-10-28 10:58:32 UTC
This week we tracked down a bug whereby "ioctl" was returning error code 11 (EAGAIN) in certain circumstances, whereas previously it was never failing.
We looked through the recent revisions to the codebase, and narrowed it down to the following:
A Linux shell script was opened with "popen", and then "pclose" was called immediately afterward ('pclose' doesn't kill the process - it waits until it's finished). I replaced these two calls with one call to "system".
The process that calls "ioctl" is a different process to the one that was using "popen/pclose" to run a script.
One of my team members theorised that the use of "system" was causing a spike in CPU/RAM usage which meant that "ioctl" came back with "Resource temporarily unavailable". My colleague said that 'system' spawns a new shell, but since we're running a script instead of a binary, I thought 'popen' would need to spawn a new shell too.
I reverted the 'system' call back to 'popen/pclose' and now everything's working fine again.
Has anyone encountered behaviour like this before?