Skip to content

Cannot keep stream open with puma server #1035

Closed
@b-dean

Description

I cannot get a stream to stay open (which is necessary for Server-Sent Events to work) with Sinatra running on Puma. I don't really have any idea why, but the connections close right away.

require 'sinatra'

set :server, :puma
set :connections, []

get '/stream', provides: 'text/event-stream' do
  stream :keep_open do |out|
    settings.connections << out
    out.callback do
      puts 'stream closed'
      settings.connections.delete(out)
    end
  end
end

Then I run curl http://localhost:4567/stream and the output is

$ ruby example.rb 
Puma 2.13.4 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Puma
stream closed
127.0.0.1 - - [14/Sep/2015 09:45:33] "GET /stream HTTP/1.1" 200 - 0.0047

If I have the server as :thin, it works fine. I don't want to use Thin though, for other reasons. And if I understand puma/puma#3 correctly, Puma can do this kind of streaming just fine.

This could be related to the problems on #962, but I'm using MRI (tested on 2.1.5p273) so it might be unrelated to any problems JRuby has.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions