{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/207","repository_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script","labels_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/207/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/207/comments","events_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/207/events","html_url":"https://github.com/Azure/azure-webjobs-sdk-script/issues/207","id":145225624,"number":207,"title":"Node: Accidentally calling context.done() twice is hard to debug","user":{"login":"brettsam","id":1089915,"avatar_url":"https://avatars.githubusercontent.com/u/1089915?v=3","gravatar_id":"","url":"https://api.github.com/users/brettsam","html_url":"https://github.com/brettsam","followers_url":"https://api.github.com/users/brettsam/followers","following_url":"https://api.github.com/users/brettsam/following{/other_user}","gists_url":"https://api.github.com/users/brettsam/gists{/gist_id}","starred_url":"https://api.github.com/users/brettsam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettsam/subscriptions","organizations_url":"https://api.github.com/users/brettsam/orgs","repos_url":"https://api.github.com/users/brettsam/repos","events_url":"https://api.github.com/users/brettsam/events{/privacy}","received_events_url":"https://api.github.com/users/brettsam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-01T16:34:51Z","updated_at":"2016-04-01T16:37:48Z","closed_at":null,"body":"Is calling `context.done()` twice from a script something we can prevent? Here's my example and what happened (this is me trying to simplify a repro -- there was a lot more code so it was harder to find the issue).\r\n\r\n    module.exports = function(context, req) {\r\n        var fs = require('fs');\r\n        fs.readFile(__dirname + '\\\\function.json.notexist', function(err, data) {\r\n            if(err) {\r\n                context.log('ERROR');\r\n                context.done(err);\r\n            }\r\n            context.log('SUCCESS');\r\n            context.done();\r\n        });\r\n    }\r\n\r\nWhen you run this:\r\n\r\n- You see a `Function started` log, but never get a corresponding `Function failed`.\r\n- You never see any logging in the console and I see no other logs in the host or function log files.\r\n- The function invocation doesn't appear in the dashboard at all.\r\n\r\nEdit: Found an easier repro as soon as I saved:\r\n\r\n    module.exports = function(context, req) {\r\n        context.log('Running...');\r\n        context.done();\r\n        context.done();\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/comments/204463083","html_url":"https://github.com/Azure/azure-webjobs-sdk-script/issues/207#issuecomment-204463083","issue_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/207","id":204463083,"user":{"login":"davidebbo","id":556238,"avatar_url":"https://avatars.githubusercontent.com/u/556238?v=3","gravatar_id":"","url":"https://api.github.com/users/davidebbo","html_url":"https://github.com/davidebbo","followers_url":"https://api.github.com/users/davidebbo/followers","following_url":"https://api.github.com/users/davidebbo/following{/other_user}","gists_url":"https://api.github.com/users/davidebbo/gists{/gist_id}","starred_url":"https://api.github.com/users/davidebbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidebbo/subscriptions","organizations_url":"https://api.github.com/users/davidebbo/orgs","repos_url":"https://api.github.com/users/davidebbo/repos","events_url":"https://api.github.com/users/davidebbo/events{/privacy}","received_events_url":"https://api.github.com/users/davidebbo/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T16:37:48Z","updated_at":"2016-04-01T16:37:48Z","body":"Agreed, a second call to `done()` should fail hard."}}