Skip to content

nix-collect-garbage: SEGFAULT and leaves database inconsistent #14891

@oxalica

Description

@oxalica

Describe the bug

journalctl of the failed unit
Dec 27 01:00:00 invar systemd[1]: Starting Nix Garbage Collector...
Dec 27 01:00:00 invar nix-gc-start[832293]: removing old generations of profile /nix/var/nix/profiles/per-user/oxa/profile
Dec 27 01:00:00 invar nix-gc-start[832293]: removing old generations of profile /nix/var/nix/profiles/system
Dec 27 01:00:00 invar nix-gc-start[832293]: removing profile version 516
Dec 27 01:00:00 invar nix-gc-start[832293]: removing profile version 515
Dec 27 01:00:00 invar nix-gc-start[832293]: removing profile version 514
Dec 27 01:00:00 invar nix-gc-start[832293]: finding garbage collector roots...
Dec 27 01:00:00 invar nix-gc-start[832293]: skipping invalid root from '/home/oxa/repo/fork/nixpkgs/pkgs/applications/misc/xmrig/result-man' to '/nix/store/jz91527709ilvjfcavfmjyp47q5a05jk-powertop-2.13-man'
Dec 27 01:00:00 invar nix-gc-start[832293]: removing stale link from '/nix/var/nix/gcroots/auto/q7mm006mf27wa7n6x53577f405y9z4wv' to '/nix/var/nix/profiles/system-514-link'
Dec 27 01:00:00 invar nix-gc-start[832293]: removing stale link from '/nix/var/nix/gcroots/auto/kj8d53bfv0ba2fd8xb5p3y9znsrwkrgw' to '/nix/var/nix/profiles/system-515-link'
Dec 27 01:00:00 invar nix-gc-start[832293]: removing stale link from '/nix/var/nix/gcroots/auto/g2rm9s51nl3mf2vxzn601w5x3l40w14m' to '/nix/var/nix/profiles/system-516-link'
Dec 27 01:00:01 invar nix-gc-start[832293]: deleting garbage...
Dec 27 01:00:03 invar systemd-coredump[832322]: Process 832293 (nix-collect-gar) of user 0 dumped core.
                                                
                                                Module libtbbmalloc.so.2 without build-id.
                                                Module libkeyutils.so.1 without build-id.
                                                Module libkrb5support.so.0 without build-id.
                                                Module libcom_err.so.3 without build-id.
                                                Module libk5crypto.so.3 without build-id.
                                                Module libkrb5.so.3 without build-id.
                                                Module libunistring.so.5 without build-id.
                                                Module libattr.so.1 without build-id.
                                                Module libpcre2-8.so.0 without build-id.
                                                Module libllhttp.so.9.3 without build-id.
                                                Module libaws-cpp-sdk-sts.so without build-id.
                                                Module libaws-cpp-sdk-cognito-identity.so without build-id.
                                                Module libaws-c-common.so.1 without build-id.
                                                Module libaws-c-sdkutils.so.1.0.0 without build-id.
                                                Module libaws-c-compression.so.1.0.0 without build-id.
                                                Module libaws-checksums.so.1.0.0 without build-id.
                                                Module libaws-c-cal.so.1.0.0 without build-id.
                                                Module libs2n.so.1 without build-id.
                                                Module libaws-c-io.so.1.0.0 without build-id.
                                                Module libaws-c-http.so.1.0.0 without build-id.
                                                Module libaws-c-auth.so.1.0.0 without build-id.
                                                Module libaws-c-s3.so.0unstable without build-id.
                                                Module libaws-c-event-stream.so.1.0.0 without build-id.
                                                Module libaws-c-mqtt.so.1.0.0 without build-id.
                                                Module libaws-crt-cpp.so without build-id.
                                                Module libgssapi_krb5.so.2 without build-id.
                                                Module libpsl.so.5 without build-id.
                                                Module libssh2.so.1 without build-id.
                                                Module libidn2.so.0 without build-id.
                                                Module libnghttp2.so.14 without build-id.
                                                Module libngtcp2.so.16 without build-id.
                                                Module libngtcp2_crypto_ossl.so.0 without build-id.
                                                Module libnghttp3.so.9 without build-id.
                                                Module libcares.so.2 without build-id.
                                                Module libicuuc.so.76 without build-id.
                                                Module libicui18n.so.76 without build-id.
                                                Module libicudata.so.76 without build-id.
                                                Module libboost_system.so.1.87.0 without build-id.
                                                Module libboost_random.so.1.87.0 without build-id.
                                                Module libboost_regex.so.1.87.0 without build-id.
                                                Module libbrotlicommon.so.1 without build-id.
                                                Module libtbb.so.12 without build-id.
                                                Module libxml2.so.16 without build-id.
                                                Module liblzma.so.5 without build-id.
                                                Module libz.so.1 without build-id.
                                                Module libbz2.so.1 without build-id.
                                                Module libzstd.so.1 without build-id.
                                                Module libacl.so.1 without build-id.
                                                Module libeditline.so.1 without build-id.
                                                Module liblowdown.so.2 without build-id.
                                                Module libgit2.so.1.9 without build-id.
                                                Module libaws-cpp-sdk-core.so without build-id.
                                                Module libaws-cpp-sdk-identity-management.so without build-id.
                                                Module libaws-cpp-sdk-s3.so without build-id.
                                                Module libaws-cpp-sdk-transfer.so without build-id.
                                                Module libseccomp.so.2 without build-id.
                                                Module libboost_url.so.1.87.0 without build-id.
                                                Module libboost_iostreams.so.1.87.0 without build-id.
                                                Module libboost_context.so.1.87.0 without build-id.
                                                Module libcpuid.so.17 without build-id.
                                                Module libbrotlienc.so.1 without build-id.
                                                Module libbrotlidec.so.1 without build-id.
                                                Module libblake3.so.0 without build-id.
                                                Module libarchive.so.13 without build-id.
                                                Module libgcc_s.so.1 without build-id.
                                                Module libstdc++.so.6 without build-id.
                                                Stack trace of thread 832293:
                                                #0  0x00007f322e8b0020 _ZN3nixL20readDerivationCommonERNS_5StoreERKNS_9StorePathEb.lto_priv.0 (libnixstore.so.2.32.4 + 0x2b0020)
                                                #1  0x00007f322e8a0c69 _ZN3nix5Store31queryPartialDerivationOutputMapB5cxx11ERKNS_9StorePathEPS0_ (libnixstore.so.2.32.4 + 0x2a0c69)
                                                #2  0x00007f322e7cce17 _ZZN3nix10LocalStore14collectGarbageERKNS_9GCOptionsERNS_9GCResultsEENKUlRKNS_9StorePathEE_clES8_ (libnixstore.so.2.32.4 + 0x1cce17)
                                                #3  0x00007f322e7ce9b2 _ZN3nix10LocalStore14collectGarbageERKNS_9GCOptionsERNS_9GCResultsE (libnixstore.so.2.32.4 + 0x1ce9b2)
                                                #4  0x00005581edf22b9c _ZL24main_nix_collect_garbageiPPc.lto_priv.0 (/nix/store/x11zi16bhr30l7sb89jbjr0v1b5hyv87-nix-2.32.4/bin/nix + 0x19fb9c)
                                                #5  0x00005581eded0821 _ZN3nix11mainWrappedEiPPc (/nix/store/x11zi16bhr30l7sb89jbjr0v1b5hyv87-nix-2.32.4/bin/nix + 0x14d821)
                                                #6  0x00007f322ea5697a _ZN3nix16handleExceptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFvvEE (libnixmain.so.2.32.4 + 0x2c97a)
                                                #7  0x00005581ede3950b main (/nix/store/x11zi16bhr30l7sb89jbjr0v1b5hyv87-nix-2.32.4/bin/nix + 0xb650b)
                                                #8  0x00007f322d82a4d8 __libc_start_call_main (libc.so.6 + 0x2a4d8)
                                                #9  0x00007f322d82a59b __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x2a59b)
                                                #10 0x00005581ede3d9b5 _start (/nix/store/x11zi16bhr30l7sb89jbjr0v1b5hyv87-nix-2.32.4/bin/nix + 0xba9b5)
                                                
                                                Stack trace of thread 832298:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832302:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832299:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832301:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832300:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832303:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832305:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832306:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832304:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832309:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832307:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832310:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832308:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832311:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832297:
                                                #0  0x00007f322d842740 __sigtimedwait (libc.so.6 + 0x42740)
                                                #1  0x00007f322d841d5c sigwait (libc.so.6 + 0x41d5c)
                                                #2  0x00007f322eb7b753 _ZN3nixL19signalHandlerThreadE10__sigset_t (libnixutil.so.2.32.4 + 0x10b753)
                                                #3  0x00007f322eb73f3d _ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFv10__sigset_tES3_EEEEE6_M_runEv (libnixutil.so.2.32.4 + 0x103f3d)
                                                #4  0x00007f322dced064 execute_native_thread_routine (libstdc++.so.6 + 0xed064)
                                                #5  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #6  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832312:
                                                #0  0x00007f322d897389 __futex_abstimed_wait_common (libc.so.6 + 0x97389)
                                                #1  0x00007f322d899e1e pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x99e1e)
                                                #2  0x00007f322e0cb480 GC_help_marker (libgc.so.1 + 0x11480)
                                                #3  0x00007f322e0cb61f GC_mark_thread (libgc.so.1 + 0x1161f)
                                                #4  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #5  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                
                                                Stack trace of thread 832313:
                                                #0  0x00007f322d91443d __poll (libc.so.6 + 0x11443d)
                                                #1  0x00007f322e7bbe49 _ZZN3nix10LocalStore14collectGarbageERKNS_9GCOptionsERNS_9GCResultsEENKUlvE_clEv.lto_priv.0 (libnixstore.so.2.32.4 + 0x1bbe49)
                                                #2  0x00007f322dced064 execute_native_thread_routine (libstdc++.so.6 + 0xed064)
                                                #3  0x00007f322d89a97a start_thread (libc.so.6 + 0x9a97a)
                                                #4  0x00007f322d922d2c __clone3 (libc.so.6 + 0x122d2c)
                                                ELF object binary architecture: AMD x86-64
Dec 27 01:00:03 invar systemd[1]: nix-gc.service: Main process exited, code=dumped, status=11/SEGV
Dec 27 01:00:03 invar systemd[1]: nix-gc.service: Failed with result 'core-dump'.
Dec 27 01:00:03 invar systemd[1]: Failed to start Nix Garbage Collector.
Dec 27 01:00:03 invar systemd[1]: nix-gc.service: Consumed 1.495s CPU time, 172.5M memory peak, 173.1M read from disk.

Disassembly of the crashing code from the core dump

Note: The value of RSI register at the point of question is zero (NULL).

Dump of assembler code for function _ZN3nixL20readDerivationCommonERNS_5StoreERKNS_9StorePathEb.lto_priv.0:
   0x00007f322e8affa0 <+0>:	push   %rbp
   0x00007f322e8affa1 <+1>:	movzbl %cl,%ecx
   0x00007f322e8affa4 <+4>:	mov    %rsp,%rbp
   0x00007f322e8affa7 <+7>:	push   %r15
   0x00007f322e8affa9 <+9>:	push   %r14
   0x00007f322e8affab <+11>:	mov    %rsi,%r14
   0x00007f322e8affae <+14>:	push   %r13
   0x00007f322e8affb0 <+16>:	push   %r12
   0x00007f322e8affb2 <+18>:	push   %rbx
   0x00007f322e8affb3 <+19>:	sub    $0x88,%rsp
   0x00007f322e8affba <+26>:	mov    %rdi,-0xa8(%rbp)
   0x00007f322e8affc1 <+33>:	mov    (%rsi),%rax
   0x00007f322e8affc4 <+36>:	lea    -0x90(%rbp),%rdi
   0x00007f322e8affcb <+43>:	mov    %fs:0x28,%rbx
   0x00007f322e8affd4 <+52>:	mov    %rbx,-0x38(%rbp)
   0x00007f322e8affd8 <+56>:	mov    %rdx,%rbx
   0x00007f322e8affdb <+59>:	mov    %rbx,%rdx
   0x00007f322e8affde <+62>:	call   *0x110(%rax)
   0x00007f322e8affe4 <+68>:	mov    %rbx,%rdi
   0x00007f322e8affe7 <+71>:	call   0x7f322e8611d0 <_ZNK3nix9StorePath17requireDerivationEv>
   0x00007f322e8affec <+76>:	mov    0x8(%rbx),%rcx
   0x00007f322e8afff0 <+80>:	mov    (%rbx),%r12
   0x00007f322e8afff3 <+83>:	cmp    $0x20,%rcx
   0x00007f322e8afff7 <+87>:	jbe    0x7f322e6f0d50 <_ZN3nixL20readDerivationCommonERNS_5StoreERKNS_9StorePathEb.lto_priv.0.cold>
   0x00007f322e8afffd <+93>:	mov    -0x90(%rbp),%rsi
   0x00007f322e8b0004 <+100>:	add    $0x21,%r12
   0x00007f322e8b0008 <+104>:	sub    $0x25,%rcx
   0x00007f322e8b000c <+108>:	lea    -0x60(%rbp),%r15
   0x00007f322e8b0010 <+112>:	mov    %r12,%r13
   0x00007f322e8b0013 <+115>:	mov    0x124d96(%rip),%rdx        # 0x7f322e9d4db0
   0x00007f322e8b001a <+122>:	mov    %rcx,%r12
   0x00007f322e8b001d <+125>:	mov    %r15,%rdi
=> 0x00007f322e8b0020 <+128>:	mov    (%rsi),%rax
   0x00007f322e8b0023 <+131>:	call   *0x10(%rax)
   0x00007f322e8b0026 <+134>:	mov    0x12460b(%rip),%r9        # 0x7f322e9d4638
   0x00007f322e8b002d <+141>:	mov    %r12,%rcx
   0x00007f322e8b0030 <+144>:	mov    %r13,%r8
   0x00007f322e8b0033 <+147>:	mov    %r15,%rdx
   0x00007f322e8b0036 <+150>:	mov    -0xa8(%rbp),%rdi
   0x00007f322e8b003d <+157>:	lea    0x18(%r14),%rsi
   0x00007f322e8b0041 <+161>:	call   0x7f322e789e00 <_ZN3nix15parseDerivationERKNS_14StoreDirConfigEONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt17basic_string_viewIcS6_ERKNS_27ExperimentalFeatureSettingsE>
   0x00007f322e8b0046 <+166>:	mov    -0x60(%rbp),%rdi
   0x00007f322e8b004a <+170>:	lea    -0x50(%rbp),%rax
   0x00007f322e8b004e <+174>:	cmp    %rax,%rdi
   0x00007f322e8b0051 <+177>:	je     0x7f322e8b0060 <_ZN3nixL20readDerivationCommonERNS_5StoreERKNS_9StorePathEb.lto_priv.0+192>
   0x00007f322e8b0053 <+179>:	mov    -0x50(%rbp),%rax
   0x00007f322e8b0057 <+183>:	lea    0x1(%rax),%rsi
   0x00007f322e8b005b <+187>:	call   0x7f322e6942d0 <_ZdlPvm@plt>
   0x00007f322e8b0060 <+192>:	mov    -0x88(%rbp),%rdi
   0x00007f322e8b0067 <+199>:	test   %rdi,%rdi

Steps To Reproduce

The nix-gc.service crashes every time when executed for me. It has already crashed 3 times before I discovered it. But I'm not sure if it's reproducible on other machines.

Expected behavior

No crashing.
Even on crashing, it should keep database consistent, ie. un-registering paths before deletion.

Metadata

> nix-env --version
nix-env (Nix) 2.32.4

Additional context

I found my nix-gc service failing because my nix database is inconsistent with store paths in filesystem.

I'm fairly sure that the database inconsistency comes from nix-collect-garbage because it is the only abnormal thing that works on it. This desktop computer has been (and is still) running for more than 10 days with no crashing, power cut, or any disk problems. The NVME disk is healthy, no warnings or errors from dmesg, and a btrfs scrub shows nothing wrong. The memory should be also fine because I played some memory-intense games on it without any issue.

I'm using nix frequently if not daily for build environment and temporary packages, it only start to show random error: getting attributes of path '/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux': No such file or directory errors when I'm updating my nixos config. The exact path in message changes. After some digging, I found that many paths are registered in database but not in filesystem:

> stat /nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux
stat: cannot statx '/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux': No such file or directory

> nix-store --realise /nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux

> stat /nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux
stat: cannot statx '/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux': No such file or directory

I double-checked it by inspecting the database directly, and it matches my guess. I guess it's being deleted by nix-collect-garbage but it crashes soon?

> cp /nix/var/nix/db/db.sqlite /tmp/nix-db.sqlite && sqlite3 /tmp/nix-db.sqlite "select * from ValidPaths where path = '/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux';"
4738445|/nix/store/br3nr5ymp1p8k9gn9zljmbnsksikj98l-stdenv-linux|sha256:eb9e891294d3a668d03cf79414ad55e5fc2e9a20f179a0ce9e25cc8f67143a7c|1766008799|/nix/store/dwp3wll5zvrx1qmjhg6fvrw89l9j55r9-stdenv-linux.drv|60488||cache.nixos.org-1:igZoCe2sXwMxSr/cYr2fVh1CRQ5RvfzKDMROOGjIZIAamHQEb2b+GrWfrlUggB/2UF1rW/uwpyMp5R1v01pvAw==|

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions