node-cron failing because of blocking IO
I'm trying to use node cron https://nodecron.com/
this is thecode in my file which should run the callback function every minute. But I am getting the error specified in the screenshot. I am running this on ubuntu wsl2. I checked task manager for memory usage and it said 45% so it's not that high. I am really unsure where to look for debugging this.

86 Replies

this is the output for
top
while the cron script is runningsounds like a bug to me
have you tried to see if there's any tuning for the cpu usage blocking thingy?
sorry I don't understand what that means. You mean look for some kind of options for this schedule function from node cron package
I'm mostly using this because some of the guys in a hackthon I am in implemented something with this functionality
and they say it works for em
and it did once for me yesterday but not now
what i meant is some setting to tune/disable the blocking
in the node-cron package?
there are these options there but they don't seem relevant to blocking besides maybe no overlap

I changed it to run every second
now it does get blocked but also runs the job
have you tried to shutdown wsl and start it again?
just save all work and anything you need, then run
wsl --shutdown
in powershellyes I did that.
wsl --shutdown
then open again with wsl
command
I'll do it once again
yeah it always succeds in the first run then fails in all subsequent ones
(this one is set to run every minute again)
how about you remove the async?
tried that before but same result
have you tried to start node as root?
you mean
yup
i'll try it now
or
sudo $(which node) ./cronJob.js
or something like that
hmm i need to specify I guess?

doesn't seem like it worked
nope
how's your cpu, in task manager?
cpu is 10 12 %
memory at 48%
it won't let me use snipping tool
try running htop as sudo
hmm I don't have it installed
is it different than just top
alright I have it running
what should I look out for
htop is top, but better
click on "cpu" until it shows from highest to lowest
after that, open a 2nd terminal window and run the command, then keep an eye on htop
if it goes, on average, above 40%, then you know what is doing that
by click on cpu do you mean in task manager
oh wait no i found it
no, in htop
I thought you can't click on linux terminal programs
it depends
htop can read mouse inputs
the shell actually has features to read the mouse clicks
ah okay
anyway I kept an eye
nothing went more than 3%
I saw the process for the node cron come for a second and go every minute
then you found a bug in it
you can either report it on github or ignore it
check if it isnt a duplicate report
and that you have the latest version of it
should i check closed too
open only has 5 issues and they don't have it
I am using latest verion
yeah, check the closed ones too
Look through them all
https://github.com/node-cron/node-cron/issues/120
GitHub
schedule to run every minute, runs several times a minute when syst...
I made a schedule to run every minute, the system is very busy every 15 minutes. 9:46 duplicating lines up with the increased usage, 9:56 and 9:57 is a quiet time, 10:00 is super busy (like 12 core...
This one said something about using background jobs that use node child process but that also didn't work
Gonna file an issue and then let it be
Can't run this anyway. Bummer
i would just file a bug report with your example
yeah I did it. listed ubuntu version, node version and package version along with everything i tried
awesome!
now, you wait a bit for triage, if they do that
and try to work through the warnings
Kk
sometimes, this is all you can do

not sure if it matters but there are 6, 7 pid for some reason
unless that is usual for cron jobs
if i were to guess, i would say that that's how node does multi-threading
but i cant promise you that this is how it works
alright. I'll just post it in the issue just to ask
go for it. doesn't hurt to ask as an aside
Ok this is stupid. I turned the wifi off and then ran the node cron and it works correctly
If i turn wifi on again it doesn't
... wth...?
I can't think of what can be blocking operations when connected to internet
that's like pressing the blinker fluid button to change the tv channel
it doesnt make any sense
Yeah same
you should report that as well
Yeah I will just after experimenting for a few minutes to see what happens if i turn off wifi while it's running
Yep same behaviour
:/ weird
super super weird
Another update. I used the crontab that comes installed by default with ubuntu and it worked fine.
Either crontab can handle waiting more gracefully and node cron immediately terminates process if there's something blocking it
Or there's something else wrong with this
Also for some reason crontab was giving me permission denied with this
* * * * * $(which node) file.js
I had to explicitly type out the path of nodethat is weirdly interesting
crontab is probably a lot better in many aspects, including reliability
but yeah, there's something weird in that node package
A bit late to the party but…why not just use CRON instead of a node implementiation of it?
seems that it is for a project, and others already implemented it with node 🤔
^ this
some of the team members run windows
and don't want to run linux
Boo windows! lol
it be like that 😔
windows has wsl
wsl is linux
is this going to be hosted in a windows or linux served?
It would just be presented by one of the guys in team during screenshare
it does run on pure linux for one of the other guys
but no one has wsl
also time limit is approching so no time to teach people how to do wsl stuff some of them are beginners so any unexpected errors could delay em further
... they dont teach you how to use linux at school?
like, linux isnt a 7-headed hydra
there are 15-minute videos on how to do the basic stuff
they certainly didn't teach me linux when i was in school
neither did they teach windows tho
to install, it's just
wsl --install
i learned linux and windows serveryes but then it's setting up git and then postgres and node then maybe another unprecedented issue pops up like with me
node? you mean, copy a line from nvm?
and run a 2nd line?
oh, wsl can also use the windows node
it can?!
you dont want it to, but it can
installing node is 2-3 commands
and one of them is
nvm use 24
or something
and if you have the correct configurstion, it can use the postgres server from windows too, without configurationsalso believe it or not people are pretty resistant to doing things they are alien to. I did recommend using wsl and teaching people if they wanted to they could even dm me. No one did of course...
well gotta figure that out which well again takes time
only one and half day left now
well, it is too late now, but for the next time
sure
linux is just better for this type of stuff
Qan adjacent question to cron. If i wanted to run something once every interval like I'm doing right now.
But if I only wanted it to run while I'm developing then what would be the solution
I don't think cron has an easy way for that. I guess you can just create a loop with bash script?
wsl --shutdown
when you're done
dont overcomplicateNo no. So imagine that i only want to run this cron job when I'm working on project 1 but i don't want it to run if I switched to working on project 2
Like project 1 has functionality to send users reminders every day via discord or email whatever. Cron does the job of running this script every day .
For dev purposes I set the interval to 2 minuted instead of 1 day. If i switch to some other project I want it to stop sending me emails messages.
So basically an easy way to pause/resume specific cron jobs
why would you have 2 projects in the same server?
if you want to do that, consider using docker or 2 different servers
I'm using wsl2 for all projects and the cron job currently. So just isolate the first project into a docker instance?
I should look into it. Haven't used it before
you should be able to stop and start it easily, using portainer or something
but im very very very very very very bad at that and cant help you besides saying "it works"
Well something to look into Either way, thanks
you're welcome
i know that docker has cron built-in, so, they can try to make it work on windows (BAD IDEA) or just throw it all on linux and it wont make a difference
if they moan and complain, they can just have it on windows