Skip to content

Returning unacquired jobserver tokens break accounting jobservers #44

Closed

Description

@mgorny

The following code:

nasm-rs/src/lib.rs

Lines 294 to 298 in 5ce627b

// Release the implicit job token for this process while NASM is running.
// Without this, the maximum number of NASM processes would be (NUM_JOBS - 1).
// This would mean that a build process with NUM_JOBS=1 would have
// no tokens left for NASM to run, causing the build to stall.
jobserver.release_raw().unwrap();

releases a jobserver token that was never acquired by nasm-rs. This is a violation of jobserver, and it is not behaving correctly with token-accounting jobserver implementations such as steve or guildmaster. In the case of steve, the attempt to write an additional token yields ENOSPC, causing unwrap() to terminate the program:

     Running `/var/tmp/portage/media-video/rav1e-0.8.1/work/rav1e-0.8.1/target/release/build/rav1e-2f7717166fc5a2d9/build-script-build`
error: failed to run custom build command for `rav1e v0.8.1 (/var/tmp/portage/media-video/rav1e-0.8.1/work/rav1e-0.8.1)`

Caused by:
  process didn't exit successfully: `/var/tmp/portage/media-video/rav1e-0.8.1/work/rav1e-0.8.1/target/release/build/rav1e-2f7717166fc5a2d9/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=nasm_x86_64

  --- stderr

  thread 'main' (1757) panicked at /var/tmp/portage/media-video/rav1e-0.8.1/work/cargo_home/gentoo/nasm-rs-0.3.0/src/lib.rs:296:33:
  called `Result::unwrap()` on an `Err` value: Os { code: 28, kind: StorageFull, message: "No space left on device" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In the case of GM, the additional "released" token will be ignored, and then the attempt to reacquire it will acquire another token (that will be released with a warning upon program termination):

nasm-rs/src/lib.rs

Lines 319 to 320 in 5ce627b

// Reacquire the implicit job token (see comments above for more info).
jobserver.acquire_raw().expect("Failed to reacquire implicit token");

My understanding is that this code is responsible for handling the "implicit slot" akin to GNU Make's. I'm afraid that such a hack is not workable per the protocol, and you need to handle such a slot locally rather than deferring that to the jobserver.

Credits to @amonakov who found the problematic code.

Activity

  1. self-assigned this
    on Dec 1, 2025
  2. FreezyLemon commented on Dec 18, 2025

    @FreezyLemon
    Contributor

    @medek if you haven't started on this yet, i could also attempt to solve this?

  3. medek commented on Dec 18, 2025

    @medek
    Owner

    @FreezyLemon nearly done, should be to push code tonight/tomorrow.

  4. added a commit that references this issue on Jan 13, 2026
  5. medek commented on Jan 13, 2026

    @medek
    Owner

    @FreezyLemon nearly done, should be to push code tonight/tomorrow.

    Well that was a lie.
    RwLock implementation fix.

    It works but not really checking if a lock gets poisoned properly. Would have liked to use std::sync::nonpoison but it's a nightly only feature right now.

    I also played around with a lock free version. It introduces unsafe code to the library though...

  6. linked a pull request that will close this issueFix for issue #44. #46on Jan 31, 2026
  7. added a commit that references this issue on Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions