node-cron failing because of blocking IO

I'm trying to use node cron https://nodecron.com/
import cron from 'node-cron';

cron.schedule('* * * * *', async () => {
console.log('first scheduler');
});
import cron from 'node-cron';

cron.schedule('* * * * *', async () => {
console.log('first scheduler');
});
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.
No description
86 Replies
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
this is the output for top while the cron script is running
ἔρως
ἔρως2mo ago
sounds like a bug to me have you tried to see if there's any tuning for the cpu usage blocking thingy?
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
what i meant is some setting to tune/disable the blocking
Ganesh
GaneshOP2mo ago
in the node-cron package?
Ganesh
GaneshOP2mo ago
there are these options there but they don't seem relevant to blocking besides maybe no overlap
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
I changed it to run every second now it does get blocked but also runs the job
ἔρως
ἔρως2mo ago
have you tried to shutdown wsl and start it again? just save all work and anything you need, then run wsl --shutdown in powershell
Ganesh
GaneshOP2mo ago
yes I did that. wsl --shutdown then open again with wsl command I'll do it once again
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
yeah it always succeds in the first run then fails in all subsequent ones (this one is set to run every minute again)
ἔρως
ἔρως2mo ago
how about you remove the async?
Ganesh
GaneshOP2mo ago
tried that before but same result
ἔρως
ἔρως2mo ago
have you tried to start node as root?
Ganesh
GaneshOP2mo ago
you mean
sudo node cornJob.js
sudo node cornJob.js
ἔρως
ἔρως2mo ago
yup
Ganesh
GaneshOP2mo ago
i'll try it now
ἔρως
ἔρως2mo ago
or sudo $(which node) ./cronJob.js or something like that
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
hmm i need to specify I guess?
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
doesn't seem like it worked
ἔρως
ἔρως2mo ago
nope how's your cpu, in task manager?
Ganesh
GaneshOP2mo ago
cpu is 10 12 % memory at 48% it won't let me use snipping tool
ἔρως
ἔρως2mo ago
try running htop as sudo
Ganesh
GaneshOP2mo ago
hmm I don't have it installed is it different than just top alright I have it running what should I look out for
ἔρως
ἔρως2mo ago
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
Ganesh
GaneshOP2mo ago
by click on cpu do you mean in task manager oh wait no i found it
ἔρως
ἔρως2mo ago
no, in htop
Ganesh
GaneshOP2mo ago
I thought you can't click on linux terminal programs
ἔρως
ἔρως2mo ago
it depends htop can read mouse inputs the shell actually has features to read the mouse clicks
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
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
Ganesh
GaneshOP2mo ago
should i check closed too open only has 5 issues and they don't have it I am using latest verion
ἔρως
ἔρως2mo ago
yeah, check the closed ones too
Ganesh
GaneshOP2mo ago
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...
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
i would just file a bug report with your example
Ganesh
GaneshOP2mo ago
yeah I did it. listed ubuntu version, node version and package version along with everything i tried
ἔρως
ἔρως2mo ago
awesome! now, you wait a bit for triage, if they do that and try to work through the warnings
Ganesh
GaneshOP2mo ago
Kk
ἔρως
ἔρως2mo ago
sometimes, this is all you can do
Ganesh
GaneshOP2mo ago
No description
Ganesh
GaneshOP2mo ago
not sure if it matters but there are 6, 7 pid for some reason unless that is usual for cron jobs
ἔρως
ἔρως2mo ago
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
Ganesh
GaneshOP2mo ago
alright. I'll just post it in the issue just to ask
ἔρως
ἔρως2mo ago
go for it. doesn't hurt to ask as an aside
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
... wth...?
Ganesh
GaneshOP2mo ago
I can't think of what can be blocking operations when connected to internet
ἔρως
ἔρως2mo ago
that's like pressing the blinker fluid button to change the tv channel it doesnt make any sense
Ganesh
GaneshOP2mo ago
Yeah same
ἔρως
ἔρως2mo ago
you should report that as well
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
:/ weird super super weird
Ganesh
GaneshOP2mo ago
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 node
ἔρως
ἔρως2mo ago
that is weirdly interesting crontab is probably a lot better in many aspects, including reliability but yeah, there's something weird in that node package
13eck
13eck2mo ago
A bit late to the party but…why not just use CRON instead of a node implementiation of it?
ἔρως
ἔρως2mo ago
seems that it is for a project, and others already implemented it with node 🤔
Ganesh
GaneshOP2mo ago
^ this some of the team members run windows and don't want to run linux
13eck
13eck2mo ago
Boo windows! lol
Ganesh
GaneshOP2mo ago
it be like that 😔
ἔρως
ἔρως2mo ago
windows has wsl wsl is linux is this going to be hosted in a windows or linux served?
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
... 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
Ganesh
GaneshOP2mo ago
they certainly didn't teach me linux when i was in school neither did they teach windows tho
ἔρως
ἔρως2mo ago
to install, it's just wsl --install i learned linux and windows server
Ganesh
GaneshOP2mo ago
yes but then it's setting up git and then postgres and node then maybe another unprecedented issue pops up like with me
ἔρως
ἔρως2mo ago
node? you mean, copy a line from nvm? and run a 2nd line? oh, wsl can also use the windows node
Ganesh
GaneshOP2mo ago
it can?!
ἔρως
ἔρως2mo ago
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 configurations
Ganesh
GaneshOP2mo ago
also 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
ἔρως
ἔρως2mo ago
well, it is too late now, but for the next time
Ganesh
GaneshOP2mo ago
sure
ἔρως
ἔρως2mo ago
linux is just better for this type of stuff
Ganesh
GaneshOP2mo ago
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?
ἔρως
ἔρως2mo ago
wsl --shutdown when you're done dont overcomplicate
Ganesh
GaneshOP2mo ago
No 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
ἔρως
ἔρως2mo ago
why would you have 2 projects in the same server? if you want to do that, consider using docker or 2 different servers
Ganesh
GaneshOP2mo ago
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
ἔρως
ἔρως2mo ago
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"
Ganesh
GaneshOP2mo ago
Well something to look into Either way, thanks
ἔρως
ἔρως2mo ago
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

Did you find this page helpful?