I have a Rails 4.1 application with a simple controller which streams a response:
class ServerSentEventsController < ApplicationController
include ActionController::Live
def index
response.headers['Content-Type'] = 'text/event-stream'
sse = ServerSentEvent.new(response.stream)
begin
loop do
sse.write(time: Time.now)
sleep 1
end
rescue IOError
# When the client disconnects, we'll get an IOError on write
ensure
sse.close
end
end
end
When I add puma to my gemfile and make a request against this route using curl
I get a streamed response as expected:
curl -i 'http://localhost:3000/sse'
<!-- truncated headers output -->
data: {"time":"2014-08-29 05:16:00 +0100"}
data: {"time":"2014-08-29 05:16:01 +0100"}
data: {"time":"2014-08-29 05:16:02 +0100"}
When I switch to thin in my gemfile and make a request the whole thing locks up. I've read in multiple places that thin can handle concurrent requests but I can't seem to make it work.
I'm starting puma simply by running bundle exec rails server
. For thin I've tried bundle exec rails server
and multiple configurations like bundle exec thin start -a 127.0.0.1 -threaded
. Nothing seems to prevent thin from locking up.
How can I get thin to accept concurrent requests?
thin
gem allows you do torails s
and you'll see when the server starts it saysBooting Thin
. I'm checking concurrency withab
as curl is only doing single requests. – Ainslie--threaded Call the Rack application in threads [experimental]
– Gagliardiab
output be sufficient here? – Ainslie