{"action":"created","issue":{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/6","repository_url":"https://api.github.com/repos/fbbdev/node-fastcgi","labels_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/6/comments","events_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/6/events","html_url":"https://github.com/fbbdev/node-fastcgi/issues/6","id":150709019,"number":6,"title":"Could not write to the response multiple times","user":{"login":"trosos","id":11371485,"avatar_url":"https://avatars.githubusercontent.com/u/11371485?v=3","gravatar_id":"","url":"https://api.github.com/users/trosos","html_url":"https://github.com/trosos","followers_url":"https://api.github.com/users/trosos/followers","following_url":"https://api.github.com/users/trosos/following{/other_user}","gists_url":"https://api.github.com/users/trosos/gists{/gist_id}","starred_url":"https://api.github.com/users/trosos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trosos/subscriptions","organizations_url":"https://api.github.com/users/trosos/orgs","repos_url":"https://api.github.com/users/trosos/repos","events_url":"https://api.github.com/users/trosos/events{/privacy}","received_events_url":"https://api.github.com/users/trosos/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"fbbdev","id":3287422,"avatar_url":"https://avatars.githubusercontent.com/u/3287422?v=3","gravatar_id":"","url":"https://api.github.com/users/fbbdev","html_url":"https://github.com/fbbdev","followers_url":"https://api.github.com/users/fbbdev/followers","following_url":"https://api.github.com/users/fbbdev/following{/other_user}","gists_url":"https://api.github.com/users/fbbdev/gists{/gist_id}","starred_url":"https://api.github.com/users/fbbdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbbdev/subscriptions","organizations_url":"https://api.github.com/users/fbbdev/orgs","repos_url":"https://api.github.com/users/fbbdev/repos","events_url":"https://api.github.com/users/fbbdev/events{/privacy}","received_events_url":"https://api.github.com/users/fbbdev/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-04-24T22:38:28Z","updated_at":"2016-05-18T16:05:15Z","closed_at":null,"body":"I am having trouble with using two consecutive write()s into a response.\r\n\r\n**Steps to reproduce:**\r\n* In node, run the following:\r\n```javascript\r\nrequire(\"node-fastcgi\").createServer(function (req, res) {\r\n    res.writeHead(200, {\"Content-Type\": \"text/html\"});\r\n    res.write(\"a\");\r\n    res.end(\"b\");\r\n}).listen(\"/tmp/socket\");\r\n```\r\n* In another terminal, run the http server:\r\n```\r\n$ node_modules/.bin/fastcgi --port=8888 --socket=/tmp/socket &\r\n```\r\n* In yet another terminal, perform the http request:\r\n```\r\n$ wget -O - http://localhost:8888/ 2>/dev/null\r\n```\r\n\r\n**Expected results:**\r\nI would expect wget to output \"ab\".\r\n\r\n**Actual results:**\r\nwget outputs only \"a\".\r\n\r\n**Note 1:**\r\nIf I used nginx with disabled buffering (\"fastcgi_buffering off;\") instead of \"node_modules/.bin/fastcgi\", the fastcgi server would crash with:\r\n```\r\nevents.js:141\r\n      throw er; // Unhandled 'error' event\r\n      ^\r\n\r\nError: write EPIPE\r\n    at exports._errnoException (util.js:870:11)\r\n    at WriteWrap.afterWrite (net.js:769:14)\r\n```\r\nand wget would output only \"a\".\r\n\r\n**Note 2:**\r\nOn the other hand, if I delay the call to res.end with setTimeout, everything works as expected:\r\n```javascript\r\nrequire(\"node-fastcgi\").createServer(function (req, res) {\r\n    res.writeHead(200, {\"Content-Type\": \"text/html\"});\r\n    res.write(\"a\");\r\n    setTimeout(function () {\r\n        res.end(\"b\");\r\n    });\r\n}).listen(\"/tmp/socket\");\r\n```"},"comment":{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/comments/220075517","html_url":"https://github.com/fbbdev/node-fastcgi/issues/6#issuecomment-220075517","issue_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/6","id":220075517,"user":{"login":"fbbdev","id":3287422,"avatar_url":"https://avatars.githubusercontent.com/u/3287422?v=3","gravatar_id":"","url":"https://api.github.com/users/fbbdev","html_url":"https://github.com/fbbdev","followers_url":"https://api.github.com/users/fbbdev/followers","following_url":"https://api.github.com/users/fbbdev/following{/other_user}","gists_url":"https://api.github.com/users/fbbdev/gists{/gist_id}","starred_url":"https://api.github.com/users/fbbdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbbdev/subscriptions","organizations_url":"https://api.github.com/users/fbbdev/orgs","repos_url":"https://api.github.com/users/fbbdev/repos","events_url":"https://api.github.com/users/fbbdev/events{/privacy}","received_events_url":"https://api.github.com/users/fbbdev/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T16:05:14Z","updated_at":"2016-05-18T16:05:14Z","body":"I'm trying to debug this and I'm seeing some bad interaction between my module and node's http module. I've been able to get two writes working, but then three writes won't work. I don't understand exactly what's going on, and since my current implementation is a total mess I fear I'll have to rewrite it completely to fix this bug.\r\n\r\nIn the meantime you can work around this by buffering writes and submitting them in a single call to `res.end`, or you can put the call to `res.end` in the callback of the last call to `res.write` (e.g. `res.write(\"a\", res.end.bind(res, \"B\"))`)."}}