You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not completely sure if this should be here or on the libuv repo, so correct me if I'm in the wrong place asking the wrong question.
I was running some benchmarks with apache benchmark on an express server and I tried to modify the number of threads in the thread pool through my index.js file with no success: process.env.UV_THREADPOOL_SIZE=1;
I ran it through the command line and it worked, then I wanted to check the amount of threads by doing a console.log(process.env.UV_THREADPOOL_SIZE) call. The thing is that I forgot to remove that line of code and when I restarted my laptop I got undefined from the console call.
So in fact when you start a fresh boot of the machine the UV_THREADPOOL_SIZE property is not set in the process.env object. Why is that?, Why the property is not added with it's default size (4 as I understand from the libuv docs) at startup?.
it does not happen to me. Just to be sure that we are on the same page: index.js is the only code you are having, or do you spawn other processes? I guess the settings in the index.js do not propagate to child processes, can you please check?
Yep just one file. Here's an extremely simplified set up to reproduce the issue:
index.js
console.log(process.env.UV_THREADPOOL_SIZE);// -> undefinedconstexpress=require("express");// EXPRESSconstapp=express();app.get("/",(req,res)=>{res.send("Hi didly ho!!!");});app.get("/fast",(req,res)=>{res.send("FAST FAST FAST!!!!");});app.listen(3000,null,()=>{console.log("express working on port 3000!!!");})
This in a folder with just express 4.16.3 installed. Run node index and this is the result:
As I mentioned this happens on Windows 7 64b (I believe most windows OS as well, haven't tested in 8 or 10 yet).
Also is worth mentioning that if I set the thread pool size via command line it is defined and set and after that I can change it through the index.js file or any other file. So doing this first:
where are you doing: process.env.UV_THREADPOOL_SIZE=1; in index.js ? I don't see it in your code (previous comment)
setting the value in the command line is the right behavior, and the right way to use it - so that different runs can use different values, if need be, without changing the source.
Yep, in that file is not there, it is just the most reduced code sample to reproduce that.
A simple solution is to create an NPM script:
SET UV_THREADPOOL_SIZE=1 && node index
But I was trying to actually avoid that. At the end I was just curious about why process.env.UV_THREADPOOL_SIZE returns undefined in Windows OS' before setting the value via CLI and not on OSX, because in OSX you can set the number of threads through a file. I just want to know if it's by design or not, if it's because how the specific OS works, etc. Just looking for an answer of why 😄
#uname
Darwin
#node
> console.log( process.env.UV_THREADPOOL_SIZE );
undefined
undefined
>
I don't see anything special with macos. If UV_THREADPOOL_SIZE is not defined in the command line (export UV_THREADPOOL_SIZE ... ) or in the source (process.env.UV_THREADPOOL_SIZE ...) it is always going to be undefined.
I fear there is a disconnect between us. Am I missing something from your explanation?
@gireeshpunathil the issue exists on windows. I'm currently running on windows 10 and Node v12. I've logged process.env, it's got no UV_THREADPOOL_SIZE property on it...
The exact same behaviour exists on Ubuntu 10 and Node V10
Reacted by Omar El Omeiri filho, Hamza, Azamat Abdullaev, Ali Afsharzadeh, Void, Jeff Mutahi, elbousidi and Maede Zebhi
Having the exact same problem on Win 7 and Node 12.22.12. By default, process.env.UV_THREADPOOL_SIZE is undefined, unless I set it from CMD with set UV_THREADPOOL_SIZE=1, for example.
re-opening, as there are at least 2 affected parties
@nodejs/libuv - is there anything special with UV_THREADPOOL_SIZE on windows? I couldn't find anything either in the code or in docs; yet the reports say that the value is not honoured.
I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js
and surprisingly that worked for me
No, it doesn't work in Windows with Node 18.20.2 (haven't tried Node versions 20, 21, 22).
You have probably set an environment variable in CMD before running node filename.js and then just reused the same terminal instance, e.g.:
SET UV_THREADPOOL_SIZE=3
node filename.js
The variable will be available within filename.js when you run it again, as long as you don't close the CMD instance.
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js
and surprisingly that worked for me
No, it doesn't work in Windows with Node 18.20.2 (haven't tried Node versions 20, 21, 22). You have probably set an environment variable in CMD before running node filename.js and then just reused the same terminal instance, e.g.:
SET UV_THREADPOOL_SIZE=3
node filename.js
The variable will be available within filename.js when you run it again, as long as you don't close the CMD instance.
Activity
gireeshpunathil commentedon Aug 14, 2018
it does not happen to me. Just to be sure that we are on the same page: index.js is the only code you are having, or do you spawn other processes? I guess the settings in the index.js do not propagate to child processes, can you please check?
rhernandog commentedon Aug 14, 2018
@gireeshpunathil Thanks for the answer.
Yep just one file. Here's an extremely simplified set up to reproduce the issue:
index.js
This in a folder with just express 4.16.3 installed. Run node index and this is the result:

As I mentioned this happens on Windows 7 64b (I believe most windows OS as well, haven't tested in 8 or 10 yet).
Also is worth mentioning that if I set the thread pool size via command line it is defined and set and after that I can change it through the
index.jsfile or any other file. So doing this first:Then running the index file gives this result:
gireeshpunathil commentedon Aug 14, 2018
where are you doing:
process.env.UV_THREADPOOL_SIZE=1;in index.js ? I don't see it in your code (previous comment)setting the value in the command line is the right behavior, and the right way to use it - so that different runs can use different values, if need be, without changing the source.
rhernandog commentedon Aug 14, 2018
Yep, in that file is not there, it is just the most reduced code sample to reproduce that.
A simple solution is to create an NPM script:
But I was trying to actually avoid that. At the end I was just curious about why
process.env.UV_THREADPOOL_SIZEreturns undefined in Windows OS' before setting the value via CLI and not on OSX, because in OSX you can set the number of threads through a file. I just want to know if it's by design or not, if it's because how the specific OS works, etc. Just looking for an answer of why 😄gireeshpunathil commentedon Aug 14, 2018
I don't see anything special with macos. If UV_THREADPOOL_SIZE is not defined in the command line (export UV_THREADPOOL_SIZE ... ) or in the source (process.env.UV_THREADPOOL_SIZE ...) it is always going to be undefined.
I fear there is a disconnect between us. Am I missing something from your explanation?
rhernandog commentedon Aug 14, 2018
No you're getting everything right, It was just I wanted to know why is undefined in one OS and not in another, just that.
gireeshpunathil commentedon Aug 27, 2018
ok, let us resolve this confusion.
Can you run:
console.log( process.env.UV_THREADPOOL_SIZE );in both win and mac to see if it differs?Can you run:
in both and see if it dffers?
$ export UV_THREADPOOL_SIZE=1
and
console.log( process.env.UV_THREADPOOL_SIZE );in UNIX and
> set UV_THREADPOOL_SIZE=1
and
console.log( process.env.UV_THREADPOOL_SIZE );in windows and see if they differ?
In all cases I would expect they don't.
gireeshpunathil commentedon Jun 10, 2019
ping @rhernandog
gireeshpunathil commentedon Jun 24, 2019
inactive, closing; pls reopen if the the issue is still relevant
Polyhistor commentedon Nov 21, 2020
@gireeshpunathil the issue exists on windows. I'm currently running on windows 10 and Node v12. I've logged process.env, it's got no
UV_THREADPOOL_SIZEproperty on it...The exact same behaviour exists on Ubuntu 10 and Node V10
lorand-horvath commentedon Oct 13, 2022
Having the exact same problem on Win 7 and Node 12.22.12. By default, process.env.UV_THREADPOOL_SIZE is undefined, unless I set it from CMD with set UV_THREADPOOL_SIZE=1, for example.
The other very strange issue that I must mention is that setting
process.env.UV_THREADPOOL_SIZE = 1;in the js file doesn't have any effect on the actual number of threads. It only does if I set it via the command line, BEFORE running node index.jsA similar report can be found here: https://stackoverflow.com/questions/68691702/process-uv-threadpool-size-size-is-not-working-in-windows
gireeshpunathil commentedon Oct 17, 2022
re-opening, as there are at least 2 affected parties
@nodejs/libuv - is there anything special with
UV_THREADPOOL_SIZEon windows? I couldn't find anything either in the code or in docs; yet the reports say that the value is not honoured.saghul commentedon Oct 17, 2022
AFAIS Node calls
uv_os_setenvhere: https://github.com/nodejs/node/blob/5fad0b93667ffc6e4def52996b9529ac99b26319/src/node_env_var.cc#L149But it does not check for the return value, and that function might fail: https://github.com/libuv/libuv/blob/97dcdb1926f6aca43171e1614338bcef067abd59/src/win/util.c#L1543
5 remaining items
preveen-stack commentedon Jun 22, 2023
windows 7 is past end of life. Wondering if we should track this
lorand-horvath commentedon Jun 22, 2023
This also happens in Windows 10, 11 etc. So yes, it needs to be fixed.
rsonaniya commentedon May 3, 2024
I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js
and surprisingly that worked for me
lorand-horvath commentedon May 3, 2024
No, it doesn't work in Windows with Node 18.20.2 (haven't tried Node versions 20, 21, 22).
You have probably set an environment variable in CMD before running
node filename.jsand then just reused the same terminal instance, e.g.:The variable will be available within filename.js when you run it again, as long as you don't close the CMD instance.
github-actions commentedon Oct 31, 2024
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
preveen-stack commentedon Nov 15, 2024
Clarification added in doc in nodejs/node#55832
moshezvi commentedon Jan 14, 2025
Can confirm: Still relevant on Windows 11 64, node v22.13.0. Commenting to keep open.
avivkeller commentedon Mar 31, 2025
Closing as completed. Sorry for the delay.
avivkeller commentedon Mar 31, 2025
If you are experiencing a similar issue, which the documentation update did not address, please open a new issue
harshal255 commentedon May 17, 2025
then Do you solve this problem ?