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

bporterfield opened this Issue May 11, 2012 · 1 comment


None yet
2 participants

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>"

  get '/js1' do
    content_type 'text/javascript'

  get '/js2' do
    content_type 'text/javascript'

run Test.new

Starting this with puma -t 1:1 -b tcp:// 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):


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

### code below is ignored

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