Skip to content

Potential race with rpm2cpio/cpio in tmt prepare #1896

Open

Description

@jeckersb

(Originally noticed in https://bodhi.fedoraproject.org/updates/FEDORA-2026-d91c9f9d5f#comment-4509248)

In the tmt prepare scripts we're piping rpm2cpio into cpio, but it looks like that might be potentially racy given during bodhi CI run this appears to have generated SIGPIPE and exited the whole thing:

17:41:22         script: cd bootc && ls -al && rpm2cpio *.src.rpm | cpio -idmv && rm -f *-vendor.tar.zstd && zstd -d *.tar.zstd && tar -xvf *.tar -C . --strip-components=1 && ls -al
[snip long uninteresting lines]
17:41:22         environment
17:41:22             out: total 16584
17:41:22             out: drwxr-xr-x. 1 root root       54 Jan  8 17:41 .
17:41:22             out: drwxr-xr-x. 1 root root     1456 Jan  8 17:41 ..
17:41:22             out: -rw-r--r--. 1 root root 16980246 Jan  8 17:41 bootc-1.12.0-1.fc44.src.rpm
17:41:22             err: ./bootc-1.12.0-vendor.tar.zstd
17:41:22             err: ./bootc-1.12.0.tar.zstd
17:41:22             err: ./bootc.spec
17:41:22             err: 33161 blocks
17:41:22         Command returned '141' (unrecognized).
17:41:22         fail: Command '/var/ARTIFACTS/work-plan-01-readonlyj35bbc8i/plans/all/plan-01-readonly/tree/tmt-prepare-wrapper.sh-default-1-default-0' returned 141.

The 141 is implying that we're getting SIGPIPE from rpm2cpio trying to write into cpio in this case. Which makes sense because we see the cpio output being emitted to stderr but we never see any output from zstd later on. So cpio is completing and then we're getting SIGPIPE.

Activity

  1. jeckersb commented on Jan 8, 2026

    @jeckersb
    CollaboratorAuthor

    AI-generated suggestions below


    The issue is that cpio -idmv is finishing and closing its stdin before rpm2cpio has finished writing all the data. When rpm2cpio tries to write to the now-closed pipe, it gets SIGPIPE and dies with signal 13.
    This commonly happens when:

    1. The cpio archive inside the src.rpm is smaller than the total rpm2cpio output
    2. Or cpio finishes extracting what it needs and exits early
      Since you're likely running this with set -e or in a context where any non-zero exit terminates the script, the SIGPIPE kills the whole thing.

    Workarounds:

    1. Ignore SIGPIPE for that command: (rpm2cpio *.src.rpm || true) | cpio -idmv
      But this masks real errors too.

    2. Check for 141 specifically:
      rpm2cpio *.src.rpm | cpio -idmv || [ $? -eq 141 ]

    3. Use a temporary file instead of a pipe:
      rpm2cpio *.src.rpm > tmp.cpio && cpio -idmv < tmp.cpio && rm tmp.cpio

    4. Trap SIGPIPE in a subshell:
      (trap '' PIPE; rpm2cpio *.src.rpm) | cpio -idmv

    Option 2 or 3 are probably cleanest depending on whether you want to avoid the temp file or not.

  2. jeckersb commented on Jan 8, 2026

    @jeckersb
    CollaboratorAuthor

    FWIW I've been running the rpm2cpio | cpio bit in a tight loop in a rawhide container for a while now and am unable to reproduce it, and simply retrying the bodhi CI run a second time succeeded, so maybe just a crazy cosmic-ray-induced flake or something 🤷

  3. cgwalters commented on Jan 8, 2026

    @cgwalters
    Member

    I don't see how that'd actually be racy, I suspect it was indeed some kind of more unusual flake such as hitting ENOSPC or the OOM killer taking out something early in the chain?

  4. cgwalters commented on Jan 8, 2026

    @cgwalters
    Member

    If we see this again we can reopen this.

  5. jeckersb commented on Jul 28, 2026

    @jeckersb
    CollaboratorAuthor

    Re-opening since I saw this again today. Burned some tokens pointing it at cpio and rpm and it came up with this:

    The problem is in libarchive's cpio writer, not in GNU cpio's reader.
    When rpm2cpio (actually rpm2archive) uses libarchive to write ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, libarchive's archive_write_close() (line 283) writes the TRAILER!!! record and likely pads it to a block boundary. This is standard cpio behavior — the SVR4 cpio format pads the archive to a 512-byte boundary after the trailer.
    On the reading side, GNU cpio reads in io_block_size chunks (default 512 bytes) via tape_fill_input_buffer. When it sees TRAILER!!! at copyin.c:1486-1487, it does break — exiting the main loop immediately without draining any remaining buffered or unbuffered input.
    The race condition:
    1. rpm2cpio (libarchive) writes the last file entry, then calls archive_write_close()
    2. archive_write_close() writes the TRAILER header + null padding to fill out the block
    3. If cpio reads the TRAILER header from a partially-filled buffer before rpm2cpio finishes writing the padding bytes, cpio exits
    4. rpm2cpio then tries to write the remaining padding → SIGPIPE
    The fix should be in GNU cpio — after seeing TRAILER!!!, it should drain remaining input to EOF (or at least read until the pipe returns EOF) rather than exiting abruptly. This is the correct behavior because:
    - The writer is legitimately padding the archive (per the cpio format spec)
    - A well-behaved pipe reader should consume all input or at least not cause the writer to fail
    - GNU tar does this — it reads past the end-of-archive markers
    The fix would be in copyin.c after the break at line 1487 — adding a drain loop after the main while(1) exits. Something like reading and discarding until EOF on the input fd.
    

    And then nudging it a little more by looking into the libarchive source:

    The full picture:
    1. rpm2cpio writes to stdout (a pipe), so libarchive sets bytes_in_last_block = 0
    2. When archive_write_close() is called, archive_write_client_close() pads the final partial buffer to a full 10240 bytes and flushes it
    3. But the 124-byte TRAILER record was the last thing written. It's sitting in the 10240-byte buffer. The close pads it with ~10116 bytes of zeroes and writes the whole 10240-byte block
    4. Meanwhile, GNU cpio has already read the chunk containing TRAILER, hit the break, and exited
    5. rpm2cpio tries to write the padded 10240-byte final block → SIGPIPE
    So the issue is a combination of two things:
    - libarchive pads the final block to 10240 bytes when writing to a pipe (designed for tape devices, not modern pipe usage)
    - GNU cpio exits immediately after seeing TRAILER without draining remaining input
    There are multiple valid places to fix this:
    1. GNU cpio: After seeing TRAILER, drain input until EOF before exiting. This is the most robust fix — cpio should be a well-behaved pipe reader regardless of what the writer pads with.
    2. libarchive: Don't pad to 10240 bytes when writing cpio format to a pipe. The 10240-byte block padding is a tar/tape convention that doesn't really apply to cpio. Though this might break other consumers expecting block-aligned output.
    3. rpm2cpio (rpm2archive.cc): Set archive_write_set_bytes_in_last_block(a, 1) before opening, so the final block isn't padded. This is the most targeted fix.
    
  6. jeckersb commented on Jul 28, 2026

    @jeckersb
    CollaboratorAuthor

    All sounds plausible, probably doesn't reproduce so easily because the timing would need to be pretty tight for rpm2cpio to

    1. write out the TRAILER
    2. probably get context switched out before it can finish writing the padding?
    3. cpio consumes TRAILER and exits early
    4. rpm2cpio gets switched back in and tries to finish writing the padding

    Should be easy enough to reproduce with a breakpoint in the right place.

  7. cgwalters commented on Jul 28, 2026

    @cgwalters
    Member

    Ah wow, definitely the kind of bug LLMs are good at digging and finding.

    I would agree with the fix being

    GNU cpio: After seeing TRAILER, drain input until EOF before exiting.

  8. cgwalters commented on Jul 30, 2026

    @cgwalters
    Member

    In the meantime I think we can workaround by redirecting from/to a file

  9. added a commit that references this issue on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions