{"action":"closed","issue":{"url":"https://api.github.com/repos/luvit/luvit/issues/356","labels_url":"https://api.github.com/repos/luvit/luvit/issues/356/labels{/name}","comments_url":"https://api.github.com/repos/luvit/luvit/issues/356/comments","events_url":"https://api.github.com/repos/luvit/luvit/issues/356/events","html_url":"https://github.com/luvit/luvit/issues/356","id":7874047,"number":356,"title":"HTTP server crashes on unexpected client socket close","user":{"login":"abitcrashy","id":2652196,"avatar_url":"https://avatars.githubusercontent.com/u/2652196?v=3","gravatar_id":"","url":"https://api.github.com/users/abitcrashy","html_url":"https://github.com/abitcrashy","followers_url":"https://api.github.com/users/abitcrashy/followers","following_url":"https://api.github.com/users/abitcrashy/following{/other_user}","gists_url":"https://api.github.com/users/abitcrashy/gists{/gist_id}","starred_url":"https://api.github.com/users/abitcrashy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abitcrashy/subscriptions","organizations_url":"https://api.github.com/users/abitcrashy/orgs","repos_url":"https://api.github.com/users/abitcrashy/repos","events_url":"https://api.github.com/users/abitcrashy/events{/privacy}","received_events_url":"https://api.github.com/users/abitcrashy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2012-10-25T20:38:28Z","updated_at":"2015-03-26T18:11:58Z","closed_at":"2015-03-26T18:11:58Z","body":"This code consistently crashes luvit http server. Same issue seems to happen also behind a reverse proxy, when proxy times out client request and closes socket.\r\n\r\n```lua\r\nlocal net = require('net')\r\nlocal string = require('string')\r\nlocal timer = require('timer')\r\n\r\nlocal HOST = '127.0.0.1'\r\nlocal PORT = process.env.PORT or 8080\r\n\r\nlocal timeoutDestroy = false\r\n\r\nlocal myReq = 'GET /crash/luvit HTTP/1.1\\r\\nHost: 127.0.0.1:'..PORT..'\\r\\nConnection: close\\r\\n\\r\\n'\r\n\r\nfor i=1, #myReq, 1 do\r\n  local request = myReq:sub(1, i)\r\n  local client\r\n  client = net.createConnection(PORT, HOST, function(err)\r\n    debug('request: ', i, request)\r\n    if err then\r\n      debug('got error, exiting', i, request)\r\n      process.exit()\r\n    end\r\n    client:write(request)\r\n    if timeoutDestroy then\r\n      timer.setTimeout(100, function() client:destroy() end)\r\n    else\r\n      client:destroy()\r\n    end\r\n  end)\r\n  client:on('end', function()\r\n    debug('end', i)\r\n  end)\r\n  client:on('error', function(err)\r\n    debug('got error, exiting', i, request)\r\n    process.exit()\r\n  end)\r\nend\r\n```\r\n\r\n<bountysource-plugin>\r\n\r\n---\r\nWant to back this issue? **[Place a bounty on it!](https://www.bountysource.com/issues/425907-http-server-crashes-on-unexpected-client-socket-close?utm_campaign=plugin&utm_content=tracker%2F133319&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F133319&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"}}