Oleg Antonyan
Oleg Antonyan

Reputation: 3113

Rails live streaming not working (freezes request)

I've a problem with live streaming feature. My controller:

class SseTestsController < ApplicationController
   include ActionController::Live
   def test1
    response.headers['Content-Type'] = 'text/event-stream'
    3.times {
      puts "writing data to the stream..."
      response.stream.write "hello world"
      sleep 1
    }
    puts "closing stream..."
    response.stream.close
    puts "closed"
  end

Route:

get 'sse' => 'sse_tests#test1'

When I make a request to /sse nothing happens. No data whatsoever sent to the client even though rails says:

Processing by SseTestsController#test1 as */*
writing data to the stream...
writing data to the stream...
writing data to the stream...
closing stream...
closed
Completed 200 OK in 3008ms (ActiveRecord: 0.0ms)

In wireshark I see only the request itself, but without any data sent back to the client:

GET /sse HTTP/1.1
User-Agent: curl/7.40.0
Host: localhost:3000
Accept: */*

and curl freezes waiting for response (so is a browser), rails app freezes and does not handle other requests. Absolutely nothing happens.

I'm using puma server

bundle exec rails server -b 0.0.0.0
=> Booting Puma
=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000


Started GET "/sse" for 127.0.0.1 at 2015-03-10 16:31:13 +0200
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by SseTestsController#test1 as */*
writing data to the stream...
writing data to the stream...
writing data to the stream...
closing stream...
closed
Completed 200 OK in 3007ms (ActiveRecord: 0.0ms)

I tried

config.preload_frameworks = true
config.allow_concurrency = true

in config/enviroments/development.rb, but it didn't help.

Rails 4.2.0, Ruby 2.0.0p247

Upvotes: 1

Views: 1049

Answers (1)

Oleg Antonyan
Oleg Antonyan

Reputation: 3113

The problem was caused by bullet gem (https://github.com/flyerhzm/bullet). Issue https://github.com/flyerhzm/bullet/issues/212

Upvotes: 3

Related Questions