Make sure no exceptions leave ignoreException()

I noticed that occasional Ctrl-C leaves *.lock files around.
`nix-daemon`'s journal logs contained crashes like:

    nix-daemon[30416]: terminate called after throwing an instance of 'nix::SysError'
    nix-daemon[30416]:   what():  error: writing to file: Broken pipe

And core dump backtraces pointed at `teriminate()` call from
destructors:

    ...
    _Unwind_Resume ()
    nix::ignoreException() ()
    nix::LocalDerivationGoal::~LocalDerivationGoal()
    ...

    void ignoreException()
    {
        try {
            throw;
        } catch (std::exception & e) {
            printError("error (ignored): %1%", e.what());
        }
    }

The crashes happen when client side closes early and printError() throws
an IO error.

The change wraps `ignoreException()` into blanket `try { ... } catch (...) {}`.

Closes: https://github.com/NixOS/nix/issues/6046
This commit is contained in:
Sergei Trofimovich 2022-02-07 16:14:57 +00:00
parent 97e02c23bd
commit 3ec02deb20

View file

@ -1358,11 +1358,15 @@ std::string shellEscape(const std::string_view s)
void ignoreException() void ignoreException()
{ {
/* Make sure no exceptions leave this function.
printError() also throws when remote is closed. */
try {
try { try {
throw; throw;
} catch (std::exception & e) { } catch (std::exception & e) {
printError("error (ignored): %1%", e.what()); printError("error (ignored): %1%", e.what());
} }
} catch (...) { }
} }
bool shouldANSI() bool shouldANSI()