{"action":"opened","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-node/issues/271","labels_url":"https://api.github.com/repos/swagger-api/swagger-node/issues/271/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-node/issues/271/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-node/issues/271/events","html_url":"https://github.com/swagger-api/swagger-node/issues/271","id":99418665,"number":271,"title":"Sails controller called twice","user":{"login":"antunes20","id":2752373,"avatar_url":"https://avatars.githubusercontent.com/u/2752373?v=3","gravatar_id":"","url":"https://api.github.com/users/antunes20","html_url":"https://github.com/antunes20","followers_url":"https://api.github.com/users/antunes20/followers","following_url":"https://api.github.com/users/antunes20/following{/other_user}","gists_url":"https://api.github.com/users/antunes20/gists{/gist_id}","starred_url":"https://api.github.com/users/antunes20/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antunes20/subscriptions","organizations_url":"https://api.github.com/users/antunes20/orgs","repos_url":"https://api.github.com/users/antunes20/repos","events_url":"https://api.github.com/users/antunes20/events{/privacy}","received_events_url":"https://api.github.com/users/antunes20/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-06T11:48:31Z","updated_at":"2015-08-06T11:48:31Z","closed_at":null,"body":"I'm using swagger with sails and i'm getting this error:\r\n\r\nd:\\nodejs\\NewsAPI\\node_modules\\sails-mongo\\node_modules\\mongodb\\lib\\utils.js:97\r\n    process.nextTick(function() { throw err; });\r\n                                        ^\r\nError: Can't set headers after they are sent.\r\n    at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)\r\n    at ServerResponse.res.setHeader (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\express\\node_modules\\connect\\lib\\patch.js:133:22)\r\n    at ServerResponse.res.set.res.header (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\express\\lib\\response.js:577:10)\r\n    at ServerResponse.res.json (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\express\\lib\\response.js:221:36)\r\n    at d:\\nodejs\\NewsAPI\\api\\controllers\\NewsController.js:34:24\r\n    at d:\\nodejs\\NewsAPI\\api\\services\\NewsService.js:24:18\r\n    at wrapper (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\node_modules\\lodash\\index.js:3602:19)\r\n    at applyInOriginalCtx (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\lib\\waterline\\utils\\normalize.js:421:80)\r\n    at wrappedCallback (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\lib\\waterline\\utils\\normalize.js:320:18)\r\n    at _normalizeCallback.callback.success (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\node_modules\\switchback\\lib\\normalize.js:33:31)\r\n    at _switch (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\node_modules\\switchback\\lib\\factory.js:48:28)\r\n    at returnResults (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\lib\\waterline\\query\\finders\\basic.js:392:9)\r\n    at d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\lib\\waterline\\query\\finders\\basic.js:272:16\r\n    at d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\lib\\waterline\\query\\finders\\operations.js:82:7\r\n    at d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\node_modules\\async\\lib\\async.js:49:16\r\n    at Object.async.forEachOf.async.eachOf (d:\\nodejs\\NewsAPI\\node_modules\\sails\\node_modules\\waterline\\node_modules\\async\\lib\\async.js:227:20)\r\n\r\n\r\nThe controller is very simple:\r\n\r\nmodule.exports = {\r\n\r\n    getAllNews: function (req, res) {\r\n        console.log(\"Hello\");\r\n        NewsService.getNewsOfTheDay(function(news){\r\n            /* news =  [{\r\n                url: \"http\",\r\n                title: \"hey\",\r\n                description: \"test\",\r\n                pubDate: \"2015-08-06T10:15:14.387Z\",\r\n                published: false\r\n            }];*/\r\n            return res.json(news);\r\n        });\r\n    }\r\n}\r\n\r\nand the NewsService:\r\n\r\nmodule.exports = {\r\n    createNews: function (news, cb) {\r\n        News.create(news).exec(function (err, news) {\r\n            if (err) cb(\"error\");\r\n            else cb(news);\r\n        });\r\n    },\r\n\r\n    getNewsOfTheDay: function (cb) {\r\n        var date = new Date();\r\n        date.setHours(0,0,0,0);\r\n        console.log(date);\r\n       News.find({pubDate: {'>=': date}, sort: 'pubDate DESC'}).exec(function(err, news){\r\n            if (err) cb(\"error\");\r\n            else cb(news);\r\n        });\r\n    }\r\n}\r\n\r\nWith the console.log() lines I can see the controller is called twice:\r\n\r\nHello\r\nThu Aug 06 2015 00:00:00 GMT+0100 (Hora de Verão de GMT)\r\nHello\r\nThu Aug 06 2015 00:00:00 GMT+0100 (Hora de Verão de GMT)\r\n\r\nswagger.yaml file:\r\n\r\nswagger: \"2.0\"\r\ninfo:\r\n  version: \"0.0.1\"\r\n  title: Hello World App\r\n# during dev, should point to your local machine\r\nhost: localhost:10010\r\n# basePath prefixes all resource paths \r\nbasePath: /\r\n# \r\nschemes:\r\n  # tip: remove http to make production-grade\r\n  - http\r\n  - https\r\n# format of bodies a client can send (Content-Type)\r\nconsumes:\r\n  - application/json\r\n# format of the responses to the client (Accepts)\r\nproduces:\r\n  - application/json\r\n  - text/plain\r\npaths:\r\n  /news:\r\n    # binds a127 app logic to a route\r\n    x-swagger-router-controller: NewsController\r\n    get:\r\n      description: Returns all News to the caller\r\n      # used as the method name of the controller\r\n      operationId: getAllNews\r\n      responses:\r\n        \"200\":\r\n          description: Success\r\n          schema:\r\n            type: array\r\n            items:\r\n              # a pointer to a definition\r\n              $ref: \"#/definitions/News\"\r\n        # responses may fall through to errors\r\n        default:\r\n          description: Error\r\n          schema:\r\n            $ref: \"#/definitions/ErrorResponse\"\r\n\r\ndefinitions:\r\n  News:\r\n    required:\r\n      - url\r\n      - title\r\n      - description\r\n      - pubDate\r\n      - published\r\n    properties:\r\n      id:\r\n        type: string\r\n      url:\r\n        type: string\r\n      description:\r\n        type: string\r\n      title:\r\n        type: string\r\n      pubDate:\r\n        type: string\r\n        format: date-time\r\n      published:\r\n        type: boolean\r\n  ErrorResponse:\r\n    required:\r\n      - message\r\n    properties:\r\n      message:\r\n        type: string\r\n\r\nAny clue about this? I also tried with very simple functions without callbacks and the problem is the same. I already tried with different browsers.\r\n"}}