Skip to content

Don't throw Interrupted from JSONLogger::write#15335

Merged
xokdvium merged 2 commits intoNixOS:masterfrom
dramforever:jsonlogger-no-interrupts
Feb 25, 2026
Merged

Don't throw Interrupted from JSONLogger::write#15335
xokdvium merged 2 commits intoNixOS:masterfrom
dramforever:jsonlogger-no-interrupts

Conversation

@dramforever
Copy link
Contributor

Motivation

$ nix --log-format internal-json eval nixpkgs#linux
@nix {"action":"msg","level":1,"msg":"\u001b[35;1mwarning:\u001b[0m unknown setting 'default-flake'"}
@nix {"action":"msg","level":1,"msg":"\u001b[35;1mwarning:\u001b[0m unknown setting 'environment'"}

Press Ctrl-C here before it gets any further, and:

Nix crashed. This is a bug. Please report this at https://github.com/NixOS/nix/issues with the following information included:

Exception: nix::Interrupted: error: interrupted by the user
Stack trace
#0  0x00007fff556052ac in __pthread_kill_implementation () from /nix/store/99al6q9wd3jg1qs43fvmllx7vakazm8x-glibc-2.42-51/lib/libc.so.6
#1  0x00007fff555ac5b8 in raise () from /nix/store/99al6q9wd3jg1qs43fvmllx7vakazm8x-glibc-2.42-51/lib/libc.so.6
#2  0x00007fff55595d38 in abort () from /nix/store/99al6q9wd3jg1qs43fvmllx7vakazm8x-glibc-2.42-51/lib/libc.so.6
#3  0x00005555aeeb4d08 in nix::(anonymous namespace)::onTerminate() [clone .lto_priv.0] ()
#4  0x00007fff5585704c in __cxxabiv1::__terminate(void (*)()) ()
   from /nix/store/biihsjk1ndvj6sf06wv5rai9v4jsnzba-gcc-15.2.0-lib/lib/libstdc++.so.6
#5  0x00007fff5584e49c in std::terminate() () from /nix/store/biihsjk1ndvj6sf06wv5rai9v4jsnzba-gcc-15.2.0-lib/lib/libstdc++.so.6
#6  0x00007fff55857440 in __cxa_rethrow () from /nix/store/biihsjk1ndvj6sf06wv5rai9v4jsnzba-gcc-15.2.0-lib/lib/libstdc++.so.6
#7  0x00007fff5656f9ec in nix::ignoreExceptionExceptInterrupt(nix::Verbosity) ()
   from /nix/store/m4s7czgh9d0ff85h1i0j0brg757fd77f-nix-util-2.33.3/lib/libnixutil.so.2.33.3
#8  0x00007fff565f8db4 in nix::JSONLogger::write(nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&) ()
   from /nix/store/m4s7czgh9d0ff85h1i0j0brg757fd77f-nix-util-2.33.3/lib/libnixutil.so.2.33.3
#9  0x00007fff565f9a84 in nix::JSONLogger::logEI(nix::ErrorInfo const&) ()
   from /nix/store/m4s7czgh9d0ff85h1i0j0brg757fd77f-nix-util-2.33.3/lib/libnixutil.so.2.33.3
#10 0x00007fff55b20ecc in nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) () from /nix/store/01vp6fqxjcvrfw0ygrzjv4flxprcp590-nix-main-2.33.3/lib/libnixmain.so.2.33.3
#11 0x00005555aee81a68 in main ()

This happens more "normally" when https://github.com/maralorn/nix-output-monitor wrapping a nix --log-format internal-json is interrupted.

Context

#14687 assumes loggers don't throw Interrupted. That wasn't true for JSONLogger.

Fix it here by generalizing 054be50, generalizing writeToStderr to writeFullLogging.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Generalize writeToStderr into writeFullLogging, with similar behavior
but taking an arbitrary fd, and reimplement writeToStderr with it as a
convenient wrapper.
Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, just needs to formatter applied. Which versions should this get backported to?

Logging should not check for interrupts. Use the new writeFullLogging
function to write JSON output to get similar behavior to SimpleLogger.

This avoids the logger itself throwing Interrupted exceptions in
handleExceptions.
@dramforever dramforever force-pushed the jsonlogger-no-interrupts branch from f52c224 to 1210100 Compare February 25, 2026 17:37
@xokdvium xokdvium added the backport 2.33-maintenance Automatically creates a PR against the branch label Feb 25, 2026
@dramforever
Copy link
Contributor Author

dramforever commented Feb 25, 2026

Should be 2.33 only I think. In < 2.33 we swallowed the exception in handleException so this doesn't actually occur.

@xokdvium xokdvium added this pull request to the merge queue Feb 25, 2026
Merged via the queue into NixOS:master with commit c8b02e6 Feb 25, 2026
16 checks passed
@internal-nix-ci
Copy link

Successfully created backport PR for 2.33-maintenance:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.33-maintenance Automatically creates a PR against the branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants