aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorSergei Trofimovich <slyich@gmail.com>2022-02-07 16:14:57 +0000
committerSergei Trofimovich <slyich@gmail.com>2022-02-07 16:20:56 +0000
commit3ec02deb20b52bd2c23fbf3c98026898857a4def (patch)
tree485bb5a54cce2e7fb12e83eaa6cfe5f5b47859ed /src/libutil/util.cc
parent97e02c23bde0515540c63081824f85ff1cebd86f (diff)
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
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc12
1 files changed, 8 insertions, 4 deletions
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()