Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

keep-alive logic can result in hanging requests #95

Closed
bporterfield opened this Issue May 11, 2012 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

bporterfield commented May 11, 2012

It seems that server keep-alive logic can result in hanging requests until the @persistent_timeout times out. My sample config.ru:

require 'sinatra'
class Test < Sinatra::Base

  get '/' do
    "<html><head><script src='/js1'></script><script src='/js2'></script></head><body>test</body></html>"
  end

  get '/js1' do
    content_type 'text/javascript'
    "console.log('1')"
  end

  get '/js2' do
    content_type 'text/javascript'
    "console.log('2')"
  end

end
run Test.new

Starting this with puma -t 1:1 -b tcp://127.0.0.1:3000 config.ru and pinging http://localhost:3000 with Chrome (which sets Connection:keep-alive) will load '/' and '/js1' but hang on '/js2' until the PERSISTENT_TIMEOUT (20 seconds).

Removing keep_alive functionality with something like this results in no hanging (but does away with any keep alive benefits):

server.rb#288

close_socket = (handle_request(env, client, parser.body, cl) == :async) ? false : true
return

### code below is ignored
Owner

evanphx commented May 16, 2012

The reason for this is that you've restricted the thread pool to 1 and only 1 thread. Chrome is multiple concurrent requests for /js1 and /js2 and keeping them both alive. Because there can only be 1 thread, puma has to time out the first request before it can move on to the second.

This isn't a bug because it's just an effect of restricting the pool size. I'll see if I can't think of a way to avoid this though.

@evanphx evanphx closed this May 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment