Bug in std::thread::spawn causing "failed to spawn thread: Os { code: 22, kind: InvalidInput, message: 'Invalid argument' }"
Nobody has claimed this yet.
- 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.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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