postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

websocket spec failing in JRuby (handler is nil)

igrigorik opened this issue · comments

/Users/igrigorik/.rvm/rubies/jruby-1.6.7/bin/jruby -S rspec spec/integration/websocket_spec.rb

Yields:

#<EventMachine::WebSocketClient:0x7047db5e>
{"SERVER_SOFTWARE"=>"Goliath", "SERVER_NAME"=>"localhost", "rack.version"=>[1, 0], "rack.errors"=>#<IO:fd 2>, "rack.multithread"=>false, "rack.multiprocess"=>false, "rack.run_once"=>false, :start_time=>1338236679.855, :time=>1338236679.855, :trace=>[], "SERVER_PORT"=>"9900", "rack.logger"=>#<Log4r::Logger:0x784f9afd>, "options"=>{:verbose=>true, :log_stdout=>true}, "status"=>{}, "config"=>{"goliath.signature"=>2}, "REMOTE_ADDR"=>"127.0.0.1", "rack.input"=>#<StringIO:0x7d5fb4f9>, "async.callback"=>#<Proc:0x166287bd@/git/goliath/lib/goliath/rack/async_middleware.rb:92>, "stream.send"=>#<Proc:0x1ebd94c6@/git/goliath/lib/goliath/websocket.rb:34>, "stream.close"=>#<Proc:0x307262ee@/git/goliath/lib/goliath/websocket.rb:35>, "stream.start"=>#<Proc:0x25bd101b@/git/goliath/lib/goliath/websocket.rb:36>, "HTTP_UPGRADE"=>"WebSocket", "HTTP_CONNECTION"=>"Upgrade", "HTTP_HOST"=>"localhost:9900", "HTTP_ORIGIN"=>"http://localhost:9900", "HTTP_SEC_WEBSOCKET_KEY1"=>"ND43| s6=20  75 )6", "HTTP_SEC_WEBSOCKET_KEY2"=>"1 9 X 5656 13 75", "CONTENT_LENGTH"=>"8", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"/ws", "QUERY_STRING"=>"", "HTTP_VERSION"=>"1.1", "SCRIPT_NAME"=>"/ws", "REQUEST_PATH"=>"/ws", "PATH_INFO"=>"/ws", "FRAGMENT"=>"", "async.headers"=>#<Method: WebSocketEndPoint(Goliath::WebSocket)#on_headers>, "async.body"=>#<Method: WebSocketEndPoint(Goliath::WebSocket)#on_body>, "async.close"=>#<Method: WebSocketEndPoint#on_close>, "goliath.request-headers"=>{"Upgrade"=>"WebSocket", "Connection"=>"Upgrade", "Host"=>"localhost:9900", "Origin"=>"http://localhost:9900", "Sec-WebSocket-Key1"=>"ND43| s6=20  75 )6", "Sec-WebSocket-Key2"=>"1 9 X 5656 13 75", "Content-Length"=>"8"}, "UPGRADE_DATA"=>"q\u001D?٬<ݭ", "handler"=>nil}
[4257:ERROR] 2012-05-28 13:24:39 :: undefined method `run' for nil:NilClass
[4257:ERROR] 2012-05-28 13:24:39 :: /git/goliath/lib/goliath/websocket.rb:76:in `response'
/git/goliath/lib/goliath/api.rb:163:in `call'
/git/goliath/lib/goliath/rack/async_middleware.rb:73:in `call'
/Users/igrigorik/.rvm/gems/jruby-1.6.7/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
/Users/igrigorik/.rvm/gems/jruby-1.6.7/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:114:in `call'
/Users/igrigorik/.rvm/gems/jruby-1.6.7/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:91:in `new'
org/jruby/RubyProc.java:258:in `call'

env.handler is nil. Is this a JRuby EM issue?

Actually both specs fail.. Second WS spec returns 500 but the test "passes" (oops)

[4258:INFO] 2012-05-28 13:26:06 :: Status: 500, Content-Length: 51, Response Time: 16.00ms
Error encountered during connection: Wrong response line

@dj2 do you have some bandwidth to take a look at this one?

Taking at look at it, EM-Websocket is not returning us a handler. There seem to be two cases where it returns nil, headers not complete and third-key not complete. I'm not sure how that can happen as, as far as I know, we have everything in response.

The relevant file is: https://github.com/igrigorik/em-websocket/blob/master/lib/em-websocket/handler_factory.rb but this seems more like an em-websockets issue then a goliath issue.

So why is this passing on MRI and broken on JRuby? Confused..

This is an encoding issue. EM-Websockets was a red-herring. When I added upgrade data to http_parser I did some silly java things which seem to have caused the encoding to get thrown off. This appears to be fixed in http_parser master already (thanks @headius)