Simple image crashes init with "removal index (is 0) should be < len (is 0)"

Hi!

I found a bug while debugging something completely unrelated (I have another image for which ssh and logs don’t work), and I want to report it.

I built an image with this Nix script:

let
  pkgs = import (builtins.fetchTarball "https://github.com/nixos/nixpkgs/archive/18036c0be90f4e308ae3ebcab0e14aae0336fe42.tar.gz") { };
  startScript = pkgs.writeShellScript "start.sh" ''
    echo HELLO

    ${pkgs.coreutils}/bin/sleep infinity
  '';
in
pkgs.dockerTools.buildLayeredImage {
  name = "broken";
  tag = "latest";

  contents = pkgs.buildEnv {
    name = "image-root";
    paths = [ pkgs.bash pkgs.coreutils ];
    pathsToLink = [ "/bin" ];
  };

  extraCommands = ''
    mkdir -p var/run/tailscale
    mkdir data
  '';
  maxLayers = 50;
  config = {
    Entrypoint = [ "${pkgs.tini}/bin/tini" "-g" "-s" "--" startScript ];
    ExposedPorts = {
      "5006/tcp" = { };
    };
    Env = [
      "NODE_ENV=production"
    ];
    WorkingDir = "/data";
  };
}

Then I built and uploaded it to a registry:

dev/nixpkgs - [nixos-unstable●] » nix-build repro.nix && skopeo copy tarball:./result docker://ghcr.io/jades-projects/fly-bug:latest      
/nix/store/8pavvkc2w5qvhlkf2z7qgx67s987zq2g-broken.tar.gz
Getting image source signatures
Copying blob 888d2b415df6 skipped: already exists  
Copying config 27f68444cb done  
Writing manifest to image destination

dev/nixpkgs - [nixos-unstable●] » flyctl machine run -a reproreprorepro ghcr.io/jades-projects/fly-bug:latest
Searching for image 'ghcr.io/jades-projects/fly-bug:latest' remotely...
image found: img_xdkzvq9d0gw49nmw
Image: ghcr.io/jades-projects/fly-bug:latest
Image size: 16 MB

Success! A machine has been successfully launched in app reproreprorepro
 Machine ID: 4d8913e7b7d587
 Instance ID: 01H746VQ1JSR720XRZY6CFJ6CE
 State: created

 Attempting to start machine...

-

And then it crashed init. I don’t know why this is crashing init; it is not really doing anything weird?

2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.040306] PCI: Fatal: No config space access function found
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info] INFO Starting init (commit: b572577)...
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info] INFO Preparing to run: `` as root
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info]thread 'main' panicked at 'removal index (is 0) should be < len (is 0)', init/src/main.rs:518:25
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info]note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.275196] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00006500
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.275706] CPU: 0 PID: 1 Comm: init Not tainted 5.15.98-g8aecaaff87 #g8aecaaff87
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.276199] Call Trace:
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.276370]  <TASK>
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.276518]  show_stack+0x52/0x5c
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.276753]  dump_stack_lvl+0x38/0x4d
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.277006]  dump_stack+0x10/0x16
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.277226]  panic+0x100/0x2b7
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.277432]  do_exit.cold+0x50/0xa0
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.277669]  do_group_exit+0x3b/0xb0
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.277919]  __x64_sys_exit_group+0x18/0x20
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.278197]  do_syscall_64+0x3b/0x90
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.278442]  entry_SYSCALL_64_after_hwframe+0x61/0xcb
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.278780] RIP: 0033:0x7f98e554069c
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.279044] Code: eb ef 48 8b 76 28 e9 25 0b 00 00 64 48 8b 04 25 00 00 00 00 48 8b b0 b0 00 00 00 e9 af ff ff ff 48 63 ff b8 e7 00 00 00 0f 05 <ba> 3c 00 00 00 48 89 d0 0f 05 eb f9 0f 1f 84 00 00 00 00 00 41 57
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.280271] RSP: 002b:00007ffd6a5280c8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.280774] RAX: ffffffffffffffda RBX: 00007f98e51bb340 RCX: 00007f98e554069c
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.281243] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000065
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.281708] RBP: 0000000000000001 R08: 0000555556db1930 R09: 0000000000000000
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.282163] R10: 00007f98e55452b0 R11: 0000000000000246 R12: 00007ffd6a528128
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.282629] R13: 00007ffd6a528138 R14: 0000000000000000 R15: 0000000000000000
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.283106]  </TASK>
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.283284] Kernel Offset: disabled
2023-08-06T01:21:25Z app[4d8913e7b7d587] sea [info][    0.283521] Rebooting in 1 seconds..

This is a bug in Fly, since it works fine in docker:

dev/nixpkgs - [nixos-unstable●] » docker load < result
ca4829bb3601: Loading layer [==================================================>]  61.44kB/61.44kB
The image broken:latest already exists, renaming the old one with ID sha256:8472d3b4f0de8548e71e78f88a51e6d41f1261ba056bfff78840c5bf78a81e78 to empty str
ing
Loaded image: broken:latest
dev/nixpkgs - [nixos-unstable●] » docker run --rm broken
HELLO
^C%                                                                                                                                                      

Suspicion:

dev/nixpkgs - [nixos-unstable●] » flyctl -a reproreprorepro machine status 4d8913e7b7d587
Machine ID: 4d8913e7b7d587
Instance ID: 01H746VQ1JSR720XRZY6CFJ6CE
State: stopped

VM
  ID            = 4d8913e7b7d587                   
  Instance ID   = 01H746VQ1JSR720XRZY6CFJ6CE       
  State         = stopped                          
  Image         = jades-projects/fly-bug:latest    
  Name          = late-pine-7670                   
  Private IP    = fdaa:0:7fa1:a7b:1a9:ec9b:a699:2  
  Region        = sea                              
  Process Group =                                  
  CPU Kind      = shared                           
  vCPUs         = 1                                
  Memory        = 256                              
  Created       = 2023-08-06T01:19:50Z             
  Updated       = 2023-08-06T01:27:30Z             
  Entrypoint    =                                  
  Command       =                                  

Entrypoint is empty for some reason, but why is that?! It’s definitely specified in the image.

OK this is my fault:

I should have used the docker-archive scheme: nix-build repro.nix && skopeo copy docker-archive:./result docker://ghcr.io/jades-projects/fly-bug:latest, and the tarball scheme was uploading a straight up bad image.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.