File flush failures during program deinitialization aren't indicated
Summary
If a flush/close of a Handle
fails during RTS deinitialization, there is no indication of a failure. Even if stderr
has already been closed, at minimum the exit status can be set to indicate a failure.
Steps to reproduce
The program
main = putStrLn "Hello, world!"
invoked as
./hello >/dev/full
will correctly report
<stdout>: commitBuffer: resource exhausted (No space left on device)
if run from ghci
or runghc
, which default stdout
to LineBuffering
. In a compiled program, stdout
is set to BlockBuffering Nothing
and the final hFlush
is done by the RTS at a time when no exceptions can be thrown and stderr
may already be closed, so nothing is reported and the program exits with status 0 (no error).
I suspect the same thing may happen with a Handle
that is garbage collected, since it may be unsafe to throw an exception at that point.
Expected behavior
Preferably report the same exception as with ghci
or runghc
, but at minimum report a non-zero exit status.
Environment
- GHC version used: 8.10.7 and 9.2.1
Optional:
- Operating System: Linux (Ubuntu 20.04)
- System Architecture: x86_64