rust-lang / rust-lang/rust

Bug in std::thread::spawn causing "failed to spawn thread: Os { code: 22, kind: InvalidInput, message: 'Invalid argument' }"

Open
#142,820 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-thread S-needs-info S-needs-repro T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

std::thread::spawn(move || {
  .....
})

I expected to see this happen: spawn new thread

Instead, this happened:

thread 'main' panicked at /work/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:729:29:
failed to spawn thread: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }

Upon further investigation using strace, it appears that the clone system call is being made with an invalid argument. Specifically, the parent_tid parameter is being passed as a pointer to tid, which seems to be incorrect.

Image

Meta

rustc --version --verbose:

binary: rustc
commit-hash: 30f168ef811aec63124eac677e14699baa9395bd
commit-date: 2025-03-05
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in library/std/src/thread/mod.rs around line 729 and reproduce the reported std:🧵:spawn failure on the stated nightly toolchain. Use strace to inspect the clone arguments, especially parent_tid, and consider the issue resolved when thread creation succeeds with valid arguments on the affected environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.