postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid websocket frame error

igrigorik opened this issue · comments

Running the spec throws an error (oddly, spec passes)

[59468:ERROR] 2012-07-19 21:43:18 :: Invalid frame received
/Users/igrigorik/.rvm/gems/ruby-1.9.3-p194/gems/em-websocket-0.3.8/lib/em-websocket/framing76.rb:66:in `process_data'
/Users/igrigorik/.rvm/gems/ruby-1.9.3-p194/gems/em-websocket-0.3.8/lib/em-websocket/handler.rb:28:in `receive_data'
/git/goliath/lib/goliath/websocket.rb:17:in `on_body'
/git/goliath/lib/goliath/request.rb:121:in `call'
/git/goliath/lib/goliath/request.rb:121:in `parse'
/git/goliath/lib/goliath/connection.rb:70:in `receive_data'
/Users/igrigorik/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:187:in `run_machine'
/Users/igrigorik/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:187:in `run'
/Users/igrigorik/.rvm/gems/ruby-1.9.3-p194/gems/em-synchrony-1.0.2/lib/em-synchrony.rb:28:in `synchrony'
/git/goliath/lib/goliath/server.rb:73:in `start'
/git/goliath/lib/goliath/test_helper.rb:51:in `server'
/git/goliath/lib/goliath/test_helper.rb:90:in `with_api'
/git/goliath/spec/integration/websocket_spec.rb:35:in `block (2 levels) in <top (required)>'

@dj2 @mloughran any ideas?

I inspected the buffer in em-websocket and it reads "#LibWebSocket::Frame:0x007fbaaa4081e0".

Looking into this briefly it looks like em-websocket-client is broken - on line 77 for em-websocket-client.rb it should read frame.next_bytes not frame.to_s.

/cc @mwylde

Just tried modifying that locally - hangs the test suite. What's surprising to me is that this seems to be a recent exception, so it would seem that it's a bug on Goliath's / em-websocket side. Or, perhaps I'm something obvious here..

@mloughran here's the part that's confusing me: these test were passing before, and em-websocket-client has not been updated for a while.. In fact, even if I freeze em-websocket to older version, the bug is still there. Don't understand where and how this popped up.

@mwylde any ideas?

Maybe libwebsocket version changed?

I just had a look at libwebsocket again, and my next_bytes suggestion was utter rubbish, sorry. The docs suggest that you can use to_bytes, but this method doesn't exist (see https://github.com/imanel/websocket-ruby/blob/v0.1/lib/libwebsocket/frame.rb). Maybe @imanel can put us straight (looks like you're working on this lib again?)

Depending on whatever you want bytes or UTF-8 you can call next_bytes or just next - both should work. There was some changes in v0.1.4 so please check under 0.1.3 if it's possible.

About working again - I'm currently working on rewrite of whole library from scratch and releasing under new name. There will be compatibility bridge that will fix couple possible bugs but will leave API unchanged, so please stick with libwebsocket for now. As soon as I finish I will make pull requests transiting depending libraries to new gem - this include also em-websocket-client(this will probably require becoming active maintainer of this gem)

I'm not really sure what could be causing the issue, but my first guess would be that the version negotiation is failing somewhere between libwebsocket and em-websocket, and em-websocket-client is getting a newer version of the protocol than it supports (currently just hixie-76, which is terribly outdated now). I should have some time to debug more fully this weekend.

Found a bug - em-websocket-client don't check which version of connection it received and don't pass it to Libwebsocket::Frame, so default is used. And current default is draft-ietf-hybi-10, which is invalid(handshake doesn't support it yet). It's most probably bug that shows between merges of branches - I will fix it and release new version.

Ok - fixed version. Please update to v0.1.5 and test again. If something will be broken then please create issue and I will take care of it asap

All green! Thanks for tracking this down guys.