Skip to content

Commit 2ac167b

Browse files
Reject zero or negative SMOL_THREADS value (#382)
SMOL_THREADS=0 creates a range 1..=0 which yields no worker threads, causing tasks spawned with smol::spawn to hang forever. Non-numeric values already fall back to 1 because parse fails, but 0 parsed successfully and produced an empty range. Add .filter(|&n| n > 0) so that a zero value falls back to the default of 1, matching the behavior for invalid values. Closes #381 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
1 parent 6176d8e commit 2ac167b

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/spawn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pub fn spawn<T: Send + 'static>(future: impl Future<Output = T> + Send + 'static
3939
// Parse SMOL_THREADS or default to 1.
4040
std::env::var("SMOL_THREADS")
4141
.ok()
42-
.and_then(|s| s.parse().ok())
42+
.and_then(|s| s.parse::<usize>().ok())
43+
.filter(|&n| n > 0)
4344
.unwrap_or(1)
4445
};
4546

0 commit comments

Comments
 (0)