Streaming API does not stream in v1.3.2 #473

Closed
bawNg opened this Issue Feb 27, 2012 · 12 comments

Comments

Projects
None yet
3 participants

bawNg commented Feb 27, 2012

Issue

Response body is only sent to client when output.close is called (no streaming) when using Sinatra 1.3.2 with Thin.

Test Case

require 'thin'
require 'sinatra/base'

class TestCase < Sinatra::Base
  set :root, File.dirname(__FILE__)

  get '/' do
    stream(:keep_open) do |output|
      output << "Streaming live data...\n"
      timer = EM.add_periodic_timer 0.5 do
        print '.'
        output << '.'
      end
      EM.add_timer 6 do
        puts 'timed out!'
        output << 'timed out!'
        output.close
        timer.cancel
      end
    end
  end
end

TestCase.run! port: 18000
Owner

rkh commented Feb 27, 2012

That is because most HTTP servers and clients don't consider a chunk of data to be complete until they receive either a newline (if they consider the data to be text) or a sufficiently large chunk of data for binary files, meaning this is a client side problem. There is not much we can do about this.

bawNg commented Feb 27, 2012

Then why does 1.3.0 and 1.3.1 work as expected?

Owner

rkh commented Feb 27, 2012

Uh, oh, that is strange. Will investigate.

stream(:keep_open) seems to work when doing a "plain" sinatra app, but not when sub classed..

Owner

rkh commented Mar 8, 2012

OK, I'll write an integration test for this running it through Thin/TCP. Wrote the foundation for this last night.

rkh added a commit that referenced this issue Mar 8, 2012

Owner

rkh commented Mar 9, 2012

The added test actually proves that the issue only exists in modular apps. I have no idea why.

i found that "plain" apps didn't work either if you used a config.ru file..

On Fri, Mar 9, 2012 at 07:37, Konstantin Haase
reply@reply.github.com
wrote:

The added test actually proves that the issue only exists in modular apps. I have no idea why.


Reply to this email directly or view it on GitHub:
#473 (comment)

Owner

rkh commented Mar 9, 2012

Did you do run Sinatra::Application or run Sinatra::Application.new?

run Sinatra::Application

Owner

rkh commented Mar 11, 2012

Cannot reproduce, your example works for me both with the current master and 1.3.2. Could you check if the tests pass for you, locally?

@rkh rkh closed this Mar 11, 2012

rkh added a commit that referenced this issue Mar 11, 2012

TestCase.run! port: 18000 works, but if you use a config.ru file:

require './test_case'
#\ -p 18000
run TestCase

and start rackup it doesn't work for me

@rkh rkh reopened this Mar 11, 2012

Owner

rkh commented Mar 11, 2012

OK, I'll check it out.

@rkh rkh closed this in 298ea5b Mar 15, 2012

danieldreier pushed a commit to danieldreier/sinatra that referenced this issue Nov 10, 2017

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