ngauthier / tubesock

Websocket interface on Rack Hijack w/ Rails support
MIT License
620 stars 43 forks source link

Rails 4.2.0.beta2 Support #32

Open tyrauber opened 10 years ago

tyrauber commented 10 years ago

Tubesock crashes in Rails4.2.0.beta with the following error:

 Started GET "/chat" for ::1 at 2014-11-09 14:20:01 -0800
 Processing by ChatController#chat as HTML
   Rendered text template (0.1ms)
 Completed -1  in 12ms (Views: 3.4ms | ActiveRecord: 0.0ms)
 Rack::Lint::LintError: Status must be >=100 seen as integer
 Exiting
 /gems/tubesock-0.2.4/lib/tubesock.rb:96:in `select': no implicit conversion of Rack::Lint::HijackWrapper into IO (TypeError)

This can be demonstrated in the sock-chat demo app by updating the Gemfile to Rails 4.2.0.beta2.

seban commented 9 years ago

Any update on that?

ngauthier commented 9 years ago

My memory is a little rust but I think the Rack Hijack spec says to return a 0, which is why tubesock does that. Perhaps that has changed? On Apr 15, 2015 6:21 AM, "Sebastian Nowak" notifications@github.com wrote:

Any update on that?

— Reply to this email directly or view it on GitHub https://github.com/ngauthier/tubesock/issues/32#issuecomment-93304979.

vmoravec commented 9 years ago

@ngauthier Looks like it has, see this: https://github.com/rack/rack/commit/36a2145561c52313efb95b910de2feb5cc105d0b

ngauthier commented 9 years ago

So perhaps it's ok to just return a 200? Can anyone try it out?

vmoravec commented 9 years ago

It returns tubesock-0.2.5/lib/tubesock.rb:100:in select': no implicit conversion of Rack::Lint::HijackWrapper into IO error

seban commented 9 years ago

It is because newer version of rack has Rack::HiJackWrapper with slighty different interface which tubesock didn't support now. I will submit a patch later today or in the weekend. Currently I monkey-patched it in my project and it works smoothly.

ngauthier commented 9 years ago

Thanks

On Fri, Apr 17, 2015 at 2:12 PM, Sebastian Nowak notifications@github.com wrote:

It is because newer version of rack has Rack::HiJackWrapper with slighty different interface which tubesock didn't support now. I will submit a patch later today or in the weekend. Currently I monkey-patched it in my project and it works smoothly.

— Reply to this email directly or view it on GitHub https://github.com/ngauthier/tubesock/issues/32#issuecomment-94042597.

seban commented 9 years ago

Spend some time on it. Locally I have problems to update tests to pass with my code so instead of PR I show you my code. My monkey-patch looks like:

def each_frame
  framebuffer = WebSocket::Frame::Incoming::Server.new(version: @version)
  io = @socket.instance_variable_get(:@io)
  while IO.select([io])
  if @socket.respond_to?(:recvfrom)
    data = io.recvfrom(2000)
  else
     data = io.readpartial(2000) #, @socket.peeraddr
  end
  break if data.empty?
  framebuffer << data
  while frame = framebuffer.next
    case frame.type
      when :close
        return
      when :text, :binary
        yield frame.data
      end
    end
  end
rescue Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::ECONNRESET, IOError, Errno::EBADF
  nil # client disconnected or timed out
end

I am sure it could be better implemented, but it shows idea what have changed. Rack::HiJackWrapper has some forward method defined https://github.com/rack/rack/blob/master/lib/rack/lint.rb#L498 maybe some of them can be used here instead of directly messing up with wrapper io instance variable.