From 3ec02deb20b52bd2c23fbf3c98026898857a4def Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Mon, 7 Feb 2022 16:14:57 +0000 Subject: 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 --- src/libutil/util.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index cd359cfee..8b317f6a8 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1358,11 +1358,15 @@ std::string shellEscape(const std::string_view s) void ignoreException() { + /* Make sure no exceptions leave this function. + printError() also throws when remote is closed. */ try { - throw; - } catch (std::exception & e) { - printError("error (ignored): %1%", e.what()); - } + try { + throw; + } catch (std::exception & e) { + printError("error (ignored): %1%", e.what()); + } + } catch (...) { } } bool shouldANSI() -- cgit v1.2.3