{"action":"created","issue":{"url":"https://api.github.com/repos/joyent/node-workflow/issues/145","labels_url":"https://api.github.com/repos/joyent/node-workflow/issues/145/labels{/name}","comments_url":"https://api.github.com/repos/joyent/node-workflow/issues/145/comments","events_url":"https://api.github.com/repos/joyent/node-workflow/issues/145/events","html_url":"https://github.com/joyent/node-workflow/issues/145","id":106617760,"number":145,"title":"Task runner does not appear to handle retry of tasks consistently on timeout","user":{"login":"keithchilders","id":7001667,"avatar_url":"https://avatars.githubusercontent.com/u/7001667?v=3","gravatar_id":"","url":"https://api.github.com/users/keithchilders","html_url":"https://github.com/keithchilders","followers_url":"https://api.github.com/users/keithchilders/followers","following_url":"https://api.github.com/users/keithchilders/following{/other_user}","gists_url":"https://api.github.com/users/keithchilders/gists{/gist_id}","starred_url":"https://api.github.com/users/keithchilders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithchilders/subscriptions","organizations_url":"https://api.github.com/users/keithchilders/orgs","repos_url":"https://api.github.com/users/keithchilders/repos","events_url":"https://api.github.com/users/keithchilders/events{/privacy}","received_events_url":"https://api.github.com/users/keithchilders/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-15T18:35:48Z","updated_at":"2015-09-15T22:31:41Z","closed_at":null,"body":"Consider the following workflow:\r\n\r\n```\r\n{\r\n    name: 'TestWorkflow',\r\n    timeout: 300,\r\n    chain: [\r\n        {\r\n            name: 'DoFirstTask',\r\n            timeout: 5,\r\n            retry: 10,\r\n            body: function(job,cb){\r\n              job.foo = (job.foo || 0) + 1;\r\n              console.log(job.foo);\r\n              if(job.foo > 5) {\r\n                console.log('i should be done now');\r\n                return cb(null,job.foo);\r\n              }\r\n            },\r\n            fallback: function(err,job,cb){\r\n              console.error(err);\r\n              return cb(err);\r\n           }\r\n        },\r\n        {\r\n            name: 'DoSecondTask',\r\n            body: function(job,cb){\r\n              console.log('second task finished');\r\n              return cb(null);\r\n            }\r\n        }\r\n    ]\r\n}\r\n```\r\n\r\nRunning this job produces the following console.log output consistently:\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\ni should be done now\r\n7\r\ni should be done now\r\n8\r\ni should be done now\r\n9\r\ni should be done now\r\n10\r\ni should be done now\r\ntask timeout error\r\n{\"name\":\"workflow-runner\",\"runner_uuid\":\"7075b17b-c198-40b8-8daa-a4ad7741d258\",\"hostname\":\"my-host\",\"pid\":9264,\"level\":40,\"job\":{\"uuid\":\"9335b419-79d1-40e3-9a20-453664b45ade\",\"name\":\"TestWorkflow\",\"execution\":\"failed\"},\"runtime\":51437,\"msg\":\"job completed\",\"time\":\"2015-09-15T18:25:51.199Z\",\"v\":0}\r\n\r\nI would expect the first invocation of cb(null) following previous timeouts of the same task to have stopped retrying and continued down the chain. Any idea what I'm doing wrong, or is this a bug?"},"comment":{"url":"https://api.github.com/repos/joyent/node-workflow/issues/comments/140565588","html_url":"https://github.com/joyent/node-workflow/issues/145#issuecomment-140565588","issue_url":"https://api.github.com/repos/joyent/node-workflow/issues/145","id":140565588,"user":{"login":"keithchilders","id":7001667,"avatar_url":"https://avatars.githubusercontent.com/u/7001667?v=3","gravatar_id":"","url":"https://api.github.com/users/keithchilders","html_url":"https://github.com/keithchilders","followers_url":"https://api.github.com/users/keithchilders/followers","following_url":"https://api.github.com/users/keithchilders/following{/other_user}","gists_url":"https://api.github.com/users/keithchilders/gists{/gist_id}","starred_url":"https://api.github.com/users/keithchilders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithchilders/subscriptions","organizations_url":"https://api.github.com/users/keithchilders/orgs","repos_url":"https://api.github.com/users/keithchilders/repos","events_url":"https://api.github.com/users/keithchilders/events{/privacy}","received_events_url":"https://api.github.com/users/keithchilders/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T22:31:41Z","updated_at":"2015-09-15T22:31:41Z","body":"Looks like the bug is here:\r\n\r\n```\r\n    function retryTask(cb) {\r\n        retries += 1;\r\n\r\n        // Set the task timeout when given:\r\n        if (timeout) {\r\n            clearTaskTimeoutId(taskTimeoutId);\r\n            // Task timeout must be in seconds:\r\n            taskTimeoutId = setTimeout(function () {\r\n                retryTimedOut = true;\r\n                return onRetryError('task timeout error', cb);\r\n            }, timeout);\r\n        }\r\n\r\n        return body(job, function (err, res) {\r\n            if (retryTimedOut) {\r\n                retryTimedOut = false;\r\n                return null;\r\n            }\r\n```\r\n\r\nIf you ever hit the timeout and retryTimedOut ever gets set to true, there's nothing to initialize it back to false for every subsequent retry, thus every non-error invocation of the callback hits the return null in the first lines of body whether that particular retry has timed out or not.\r\n\r\nI just want to confirm whether there's some reason for this to work this way before submitting a PR to fix."}}