Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Midnight problem #400

Closed
TeodorKolev opened this issue Jan 30, 2019 · 7 comments
Closed

Midnight problem #400

TeodorKolev opened this issue Jan 30, 2019 · 7 comments

Comments

@TeodorKolev
Copy link

TeodorKolev commented Jan 30, 2019

Everything works fine till midnight. Then cron job begin to produce timeout requests. Server time is set to UTC. I have also tried with different timezones specified, or without timezone. Same error results. Socket hang up on my requests after midnight.. Every cron tick after midnight is fired with couple of minutes delay and it's http inner method response produce TimeoutError: ResourceRequest timed out. Does anyone has any idea why it breaks after 00:00?

const createCronJob = passedFunction =>
  new CronJob('00,10,20,30,40,50 * * * *', () => {
    return passedFunction();
  }, null, true, 'UTC');

node-cron version: 1.6

@ncb000gt
Copy link
Member

ncb000gt commented Feb 9, 2019

@TeodorKolev Hi, I just want to make sure I understand the problem you're having.

The cron runs normally and the onTick fires as expected until midnight because the onTick doesn't fire immediately at midnight the way you expected, but instead is delayed?

@TeodorKolev
Copy link
Author

@ncb000gt exactly

@ncb000gt
Copy link
Member

ncb000gt commented Feb 9, 2019

I setup a test that should exemplify the issue you noted and it seems to pass fine. Locally. Obviously, it's a test and not the real env...so, I also ran a test by changing my machine time to 11:59:50, and the cron triggered when expected.

	it.only('should trigger onTick at midnight', function() {
		var c = 0;
		var d = new Date('12/31/2014');
		d.setSeconds(59);
		d.setMinutes(59);
		d.setHours(23);
		var clock = sinon.useFakeTimers(d.getTime());

		var job = new cron.CronJob({
			cronTime: '00 * * * * *',
			onTick: function() {
				c++;
			},
			start: true,
			timeZone: 'UTC'
		});

		clock.tick(1000); // move clock 1 second
		expect(c).to.eql(1);

		clock.restore();
		job.stop();
		expect(c).to.eql(1);
	});

screen shot 2019-02-10 at 12 00 19 am

Note that I'm in EST, hence the difference in the time representation.

So, I have a couple of questions.

Is it possible that the endpoint you're trying to hit is doing something at midnight? I've known places to put an automatic restart into systems for one reason or another, but this might be the reason for the delay and subsequent timeout you're seeing.

Did you add any logging to the beginning of your onTick callback or the module itself to see when the onTick itself actually fires vs the timeout response?

Let me know. Hopefully this is helpful, and I'm going to commit the test for tracking purposes.

ncb000gt added a commit that referenced this issue Feb 9, 2019
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
@intcreator
Copy link
Collaborator

this issue is described in a passing test so I'm going to close it for now. feel free to reopen it if you're still experiencing this issue

@Suryapratapsoniigt

This comment was marked as off-topic.

@sheerlox

This comment was marked as off-topic.

@sheerlox

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants