{"action":"created","issue":{"url":"https://api.github.com/repos/node-schedule/node-schedule/issues/369","repository_url":"https://api.github.com/repos/node-schedule/node-schedule","labels_url":"https://api.github.com/repos/node-schedule/node-schedule/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/node-schedule/node-schedule/issues/369/comments","events_url":"https://api.github.com/repos/node-schedule/node-schedule/issues/369/events","html_url":"https://github.com/node-schedule/node-schedule/issues/369","id":239402307,"number":369,"title":"Job still fired after .cancel()","user":{"login":"Clbt","id":5502348,"avatar_url":"https://avatars2.githubusercontent.com/u/5502348?v=4","gravatar_id":"","url":"https://api.github.com/users/Clbt","html_url":"https://github.com/Clbt","followers_url":"https://api.github.com/users/Clbt/followers","following_url":"https://api.github.com/users/Clbt/following{/other_user}","gists_url":"https://api.github.com/users/Clbt/gists{/gist_id}","starred_url":"https://api.github.com/users/Clbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clbt/subscriptions","organizations_url":"https://api.github.com/users/Clbt/orgs","repos_url":"https://api.github.com/users/Clbt/repos","events_url":"https://api.github.com/users/Clbt/events{/privacy}","received_events_url":"https://api.github.com/users/Clbt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-06-29T08:28:16Z","updated_at":"2017-08-29T18:19:16Z","closed_at":null,"body":"Hello there,\r\n\r\nWe're having a weird issue with node-schedule.  When having a lot of jobs firing at the same time (a lot = more than 20) and deleting another job one day after it was created, this job is still fired on its due time, every day. \r\n\r\nHere's our process: \r\nWe have three kinds of jobs, and we're saving each of them in an array.  \r\n```javascript\r\nthis.scheduler = {\r\n    true: [],\r\n    false: [],\r\n    later: []\r\n};\r\n```\r\nAfter initializing this array, we process our recurrence rule which is a bit too complicated to show here.\r\nIf we don't do anything after that, the reccurrence rule works fine and jobs are fired whenever they're supposed to. \r\n\r\nThe issue happens after we've deleted the job (if we delete it one day or more after its creation).\r\n\r\nHere's the way we're deleting our jobs:\r\n```javascript\r\ndeleteScheduledJobs = function() {\r\n\tfor (let laterJob of this.scheduler.later) {\r\n\t\tif (laterJob != null) {\r\n\t\t\tlaterJob.cancel();\r\n\t\t}\r\n\t}\r\n\tfor (let trueJob of this.scheduler.true) {\r\n\t\tif (trueJob != null) {\r\n\t\t\ttrueJob.cancel();\r\n\t\t}\r\n\t}\r\n\tfor (let falseJob of this.scheduler.false) {\r\n\t\tif (falseJob != null) {\r\n\t\t\tfalseJob.cancel();\r\n\t\t}\r\n\t}\r\n\r\nthis.scheduler = {\r\n\t\ttrue: [],\r\n\t\tfalse: [],\r\n\t\tlater: []\r\n\t};\r\n```\r\nWhen looping on `schedule.scheduleJobs` and listing pending invokations before canceling, we have this:\r\n```json\r\nJOB=<Anonymous Job 97> - PENDING INVOCATIONS=[{\"fireDate\":\"2017-05-31T08:00:00.446Z\",\"recurrenceRule\":{\"recurs\":true,\"year\":null,\"month\":null,\"date\":null,\"dayOfWeek\":null,\"hour\":10,\"minute\":0,\"second\":0}}]\r\nJOB=<Anonymous Job 98> - PENDING INVOCATIONS=[{\"fireDate\":\"2017-05-31T08:10:00.447Z\",\"recurrenceRule\":{\"recurs\":true,\"year\":null,\"month\":null,\"date\":null,\"dayOfWeek\":null,\"hour\":10,\"minute\":10,\"second\":0}}]\r\n```\r\nAfter canceling those jobs, they don't appear in `schedule.scheduledJobs` and when doing something like `myJob.pendingInvocations()` the result is empty. As it should be. **However, the job is still fired at the correct time even though it's been cancelled**. And we know it's been fired because the callback is fired.\r\n\r\nWe have absolutely no idea of where the issue is coming from or what we may have done wrong. It seems wer'e canceling jobs properly. \r\n\r\nIs there any kind of stress issue on node-schedule that we're not aware of? \r\nIs there any way to see what could be firing our callback if not the jobs?\r\n\r\nThank you, we'll appreciate any kind of help!"},"comment":{"url":"https://api.github.com/repos/node-schedule/node-schedule/issues/comments/325750442","html_url":"https://github.com/node-schedule/node-schedule/issues/369#issuecomment-325750442","issue_url":"https://api.github.com/repos/node-schedule/node-schedule/issues/369","id":325750442,"user":{"login":"nnoto","id":7365145,"avatar_url":"https://avatars3.githubusercontent.com/u/7365145?v=4","gravatar_id":"","url":"https://api.github.com/users/nnoto","html_url":"https://github.com/nnoto","followers_url":"https://api.github.com/users/nnoto/followers","following_url":"https://api.github.com/users/nnoto/following{/other_user}","gists_url":"https://api.github.com/users/nnoto/gists{/gist_id}","starred_url":"https://api.github.com/users/nnoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nnoto/subscriptions","organizations_url":"https://api.github.com/users/nnoto/orgs","repos_url":"https://api.github.com/users/nnoto/repos","events_url":"https://api.github.com/users/nnoto/events{/privacy}","received_events_url":"https://api.github.com/users/nnoto/received_events","type":"User","site_admin":false},"created_at":"2017-08-29T18:19:16Z","updated_at":"2017-08-29T18:19:16Z","body":"I was finally able to reproduce this issue fairly consistently with this test. \r\n1. 10000 jobs were scheduled to run every 10 seconds\r\n2. All jobs are cancelled after 20 seconds\r\n3. More often than not, at least one job will continue running, despite witnessing a successful cancellation in the logs. I've ran it a few times where none of the jobs continued running, but on the majority of runs, at least one job continues to get scheduled. \r\n4. nscheduler.scheduledJobs begins printing after all jobs have been cancelled. It returns an empty object in the scenario where a cancelled job is still getting scheduled\r\n\r\n```\r\nconst nscheduler = require('node-schedule');\r\n\r\nlet name = 'testSched';\r\nlet flag = false;\r\n\r\nfor (let i = 0; i < 10000; i++) {\r\n  let schedName = name + i;\r\n  nscheduler.scheduleJob(schedName, '*/10 * * * * *', function () {\r\n      console.log(schedName + ' ran successfully');\r\n      if (flag) {\r\n        console.log(JSON.stringify(nscheduler.scheduledJobs));\r\n\r\n      }\r\n\r\n  });\r\n}\r\n\r\nsetTimeout(function() {\r\n  for (let i = 0; i < 10000; i++) {\r\n    let schedName = name + i;\r\n    if (nscheduler.cancelJob(schedName) === false) {\r\n      console.log('Schedule ' + schedName + ' not currently active.');\r\n    } else {\r\n      console.log('Schedule ' + schedName + ' removed from scheduler.');\r\n    }\r\n  }\r\n  flag = true;\r\n}, 20000)\r\n```"}}
{"actor":{"display_login":"nnoto"}}