Description
Describe the bug
cabal 3.4.0.0 uses the use_process_jobs
flag for all created processes. See: #6529 and #6536
The problem is that hsc2hs.exe
also uses the use_process_jobs
flag to create its sub-processes (like when it calls gcc.exe
)
See: https://github.com/haskell/hsc2hs/blob/24100ea521596922d3edc8370b3d9f7b845ae4cf/Common.hs#L43
This is a problem because on Windows 7:
A process can be associated only with a single job. [...] If a process is associated with a job, all child processes it creates are associated with that job by default.
which is documented by Microsoft here: https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-assignprocesstojobobject (Note that on Windows 8 and above there is no problem)
What ends up happening is that inside hsc2exe.exe
, inside createProcess
, the call to the Win32 function AssignProcessToJobObject
fails:
"C:\ghc-8.10.3\bin\hsc2hs.exe" "@C:\Users\bitc\myproject\dist-newstyle\build\x86_64-windows\ghc-8.10.3\myproject-0.6.2.3\build\My\Module\hsc258F.txt"
hsc2hs.exe: C:\ghc-8.10.3\lib\../mingw/bin\gcc.exe: createProcess: permission denied (Permission denied)
Explanation: hsc2hs.exe
is running inside a "job" (that was created by cabal.exe
). hsc2hs.exe
launches gcc.exe
and now gcc.exe
is also running inside the same "job". Immediately after launching gcc.exe
, hsc2hs.exe
creates a new "job" and tries to put gcc.exe
into this new job (AssignProcessToJobObject
) but this call fails because gcc.exe
already is part of a "job" (the one it inherited from hsc2hs.exe
).
AssignProcessToJobObject
is called here: https://github.com/haskell/process/blob/5a0cbd46eca6d30b78726688058b7fd258a2253d/cbits/runProcess.c#L742
Solution
When cabal calls hsc2hs.exe
it should set use_process_jobs = False
, so that hsc2hs.exe
will be able to use this flag. This is valid because hsc2hs.exe
doesn't use exec
, it properly awaits on its own children.
When cabal calls ghc.exe
, gcc.exe
, or other tools, it may set use_process_jobs = True
(because they themselves don't set the use_process_jobs
flag)
Another Solution
It may be possible to utilize CREATE_BREAKAWAY_FROM_JOB
somehow (either in cabal or in hsc2hs). See: https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-assignprocesstojobobject
Alternative Solution
cabal should officially drop support for Windows 7 (a shame)
System information
- Windows 7
- cabal 3.4.0.0
Thank you