mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
[GH-ISSUE #503] The global thread pool has not been initialized.: ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized } #221
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Joshix-1 on GitHub (Jun 14, 2025).
Original GitHub issue: https://github.com/bootandy/dust/issues/503
Fix:
Also doesn't happen if I set
RAYON_NUM_THREADS=1or to another up to 19@bootandy commented on GitHub (Jun 16, 2025):
Nope.
I can not replicate this on my machine.
The problem here is that the thread pool has already been initialized by something else in your machine.
Also, you've removed the call to
build_thread_poolwhich assigns the stack size correctly on low memory machines.This part of the code is weird and tricky. The above code is an unpleasant compromise that (used) to stop the error you printed occurring.
I can't figure out why you are seeing it.
Does your code enter the if:
if cfg!(target_pointer_width = "64") {? - if so the thread pool should be built there - if not removing this 'if' will not do anything.@Joshix-1 commented on GitHub (Jun 16, 2025):
Same. Doesn't really make sense.
Yes, otherwise my patch wouldn't do anything.
Seems like the problem wasn't a pointer width of 32. Other stuff can cause the same issue.
Does that really improve stuff? Are the defaults rayon provides that bad?
I see two possible solutions:
@bootandy commented on GitHub (Jun 20, 2025):
Yes it does, we had to add this to stop exactly the same error you are seeing now:
https://github.com/bootandy/dust/issues?q=is%3Aissue%20state%3Aclosed%20ThreadPoolBuildError
Some of the previous PRs were doing (1) in your suggestion list.
I really don't understand why you see:
That's exactly what the code you removed in your suggestion is doing - it's initalizing the global thread pool and catching the error if it causes a problem.
The error you are seeing is from the dir_walker.rs file (The first place Rayon is used to walk the filesystem). - Yet you removed code for initalizing rayon. This doesn't make any sense to me.
@bootandy commented on GitHub (Jun 20, 2025):
Yeah, I think you are right here, maybe we should remove the 'if'.
@bootandy commented on GitHub (Jun 20, 2025):
does
dust -T 1do anything ? - This should run dust with 1 thread.@bootandy commented on GitHub (Jun 20, 2025):
What happens on your box if you use this instead:
Mine does:
Which ^ makes sense to me, one call to init the thread pool, and the second failed but the panic is caught by the logic.
@bootandy commented on GitHub (Jun 20, 2025):
So here's my thoughts:
I need to call
build_thread_pool- but its wrapped in a panic unwrap incase it goes wrong - (which in my eyes should make it completely safe).If you can tweak
build_thread_poolor add another call to make your build work then I'll accept a PR.(And maybe we should loose
if cfg!(target_pointer_width = "64") {in init_rayon)@Joshix-1 commented on GitHub (Jun 20, 2025):
Works with numbers from 1 to 19 (inclusive)
I looked a bit into it and it seems like rayon fails to create the 20th thread.
So it seems like it can't spawn the 20th thread because of some sort of stack limitations
@bootandy commented on GitHub (Jun 23, 2025):
This bit is interesting, its different to mine.
@bootandy commented on GitHub (Jun 23, 2025):
I think its because if you set the stack_size you call
pool.stack_size(stack_size_param);which somehow initializers the thread library correctly@bootandy commented on GitHub (Jun 23, 2025):
cargo run -- -S 1048576I imagine this would work for you too.
@bootandy commented on GitHub (Jun 23, 2025):
If you change init_rayon to catch your IOError and then set the default stack size and re-try and create the thread pool, does that work ?
@Joshix-1 commented on GitHub (Jun 23, 2025):
Yep, that works too. But with the default for high memory (
1024 ** 3) https://github.com/bootandy/dust/blob/master/src/main.rs#L414 it doesn't work:With
cargo runoutputs:@bootandy commented on GitHub (Jun 23, 2025):
edit: No that was a dumb comment.
@bootandy commented on GitHub (Jul 5, 2025):
So in summary: If we look at the
build_thread_poolfunction. It seems that it 'works' if we set stack_size or number of threads - So it looks like we have to alter the ThreadPool in some way inorder for the code to work.@bootandy commented on GitHub (Jul 5, 2025):
https://github.com/bootandy/dust/pull/511
Does this fix it ?
@bootandy commented on GitHub (Jul 5, 2025):
I think this error occurs when the system doesn't have enough memory - I have seen this error when setting the stack size to be much too large.
@bootandy commented on GitHub (Jul 5, 2025):
I'm optimistic about this one:
https://github.com/bootandy/dust/pull/512
@Joshix-1 commented on GitHub (Jul 5, 2025):
With available memory of 44635316224 Bytes (41.569 GiB) I can't get 32 threads with stack size of 1073741824 Bytes (1 GiB) to work.
@Joshix-1 commented on GitHub (Jul 5, 2025):
And
./target/release/dust -T 19uses only a few MiB of RAM, so it's not a memory issue. There is some other limit.The
max memory sizeof 20Gb could be the reason for the failure. It breaks starting with-T 20@bootandy commented on GitHub (Jul 5, 2025):
Hmm, that'd interesting.
surprised that you can't get 32 threads running.
https://docs.rs/rayon/latest/rayon/struct.ThreadPoolBuilder.html#method.stack_size
If there are any other functions we could call in ThreadPoolBuilder let me know and we'll try it.
@bootandy commented on GitHub (Jul 7, 2025):
i hope this is fixed in 1.2.2