eventmachine / evma_httpserver

An evented http server built on top of eventmachine
http://rubyeventmachine.com
116 stars 44 forks source link

send_response intermittent failure #34

Open catmando opened 8 years ago

catmando commented 8 years ago

The puffing billy gem is using evma_httpserver to simulate responses to javascript clients.

Intermittently a response is not getting back to the browser.

The puffing billy code (monkey patched to provide logging looks like this:)

Billy::ProxyConnection.send(:define_method, :send_response) do |response|
  Billy.log(:info, "puffing-billing: send_response #{response[:status]}, #{response[:headers]}, '#{response[:content][0..10]}'")
  res = EM::DelegatedHttpResponse.new(self)
  res.status = response[:status]
  res.headers = response[:headers]
  res.content = response[:content]
  res.send_response
  Billy.log(:info, "puffing-billing: send_response SENT!")
end

In the resulting log I see this:

puffing-billing: send_response 200, {"Content-Type"=>"application/javascript;charset=utf-8", "Connection"=>"close", "Status"=>"200", "X-Powered-By"=>"Phusion Passenger (mod_rails/mod_rack) 3.0.11", "Content-Length"=>"1708", "Server"=>"nginx/1.0.14 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)"}, 'jQuery11200'
puffing-billing: send_response SENT!

but the browser log looks like this:

screen shot 2016-03-11 at 3 03 14 pm

This happens about 25 % of the time. When the response is successful everything looks exactly the same except in the browser net log I see 200 ... and 1708 bytes received.

The problem is NOT browser specific. I have tried the same scenario using poltergeist, with the same results.

It would be very difficult to get this into an isolated test case that I could share, but I would be happy to add logging to evma_httpserver, if I could have some clues WHAT to investigate. Also would be happy to set up a co-debug session on cloud9.

catmando commented 8 years ago

Turns out this was a problem inside of puffing billy. BUT in case anybody cares the problem was that the Content-Length header was being supplied, but had a different value than the actual Content-Length. Not sure whether this broke evma_httpserver, EM, or both firefox/poltergeist, but at any rate simply removing the Content-Length header (and I guess letting evma_httpserver compute it) fixed the problem.

mackermans commented 8 years ago

Hey @catmando, looks like you had the same issue as I had. Check out this PR https://github.com/oesmith/puffing-billy/pull/162