Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding issue when using JRuby #18

Closed
samflores opened this issue Mar 19, 2013 · 4 comments
Closed

Encoding issue when using JRuby #18

samflores opened this issue Mar 19, 2013 · 4 comments

Comments

@samflores
Copy link

I'm facing an encoding compatibility error when trying to use faye-websocket with Goliath server in JRuby 1.7.3 (1.9 mode)

Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
                    + at org/jruby/RubyString.java:1113
  handshake_signature at /home/samuel/.gem/jruby/1.9.3/gems/faye-websocket-0.4.7-java/lib/faye/websocket/draft76_parser.rb:35
                parse at /home/samuel/.gem/jruby/1.9.3/gems/faye-websocket-0.4.7-java/lib/faye/websocket/draft76_parser.rb:46
                parse at /home/samuel/.gem/jruby/1.9.3/gems/faye-websocket-0.4.7-java/lib/faye/websocket.rb:172
             __send__ at org/jruby/RubyBasicObject.java:1683
              receive at /home/samuel/.gem/jruby/1.9.3/gems/faye-websocket-0.4.7-java/lib/faye/websocket.rb:202
         receive_data at /home/samuel/.gem/jruby/1.9.3/gems/faye-websocket-0.4.7-java/lib/faye/adapters/goliath.rb:10
       event_callback at /home/samuel/.gem/jruby/1.9.3/gems/eventmachine-1.0.3-java/lib/eventmachine.rb:1484
        eventCallback at /home/samuel/.gem/jruby/1.9.3/gems/eventmachine-1.0.3-java/lib/jeventmachine.rb:92
          run_machine at /home/samuel/.gem/jruby/1.9.3/gems/eventmachine-1.0.3-java/lib/jeventmachine.rb:111
                  run at /home/samuel/.gem/jruby/1.9.3/gems/eventmachine-1.0.3-java/lib/eventmachine.rb:187
            synchrony at /home/samuel/.gem/jruby/1.9.3/gems/em-synchrony-1.0.3/lib/em-synchrony.rb:38
                start at /home/samuel/.gem/jruby/1.9.3/gems/goliath-1.0.1/lib/goliath/server.rb:73
           run_server at /home/samuel/.gem/jruby/1.9.3/gems/goliath-1.0.1/lib/goliath/runner.rb:296
                  run at /home/samuel/.gem/jruby/1.9.3/gems/goliath-1.0.1/lib/goliath/runner.rb:221
                 run! at /home/samuel/.gem/jruby/1.9.3/gems/goliath-1.0.1/lib/goliath/application.rb:111
              Goliath at /home/samuel/.gem/jruby/1.9.3/gems/goliath-1.0.1/lib/goliath/application.rb:129
@jcoglan
Copy link
Collaborator

jcoglan commented Mar 19, 2013

This appears to be a bug in the http_parser gem, which is used by goliath. Take the following script: it contains the raw bytes of a hixie-76 handshake request, turns them into a string, and tells Http::Parser to parse them:

require 'http/parser'

bytes = [ 71, 69, 84, 32, 47, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 85,
          112, 103, 114, 97, 100, 101, 58, 32, 87, 101, 98, 83, 111, 99, 107,
          101, 116, 13, 10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58,
          32, 85, 112, 103, 114, 97, 100, 101, 13, 10, 72, 111, 115, 116, 58,
          32, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 55, 48, 48, 49,
          13, 10, 79, 114, 105, 103, 105, 110, 58, 32, 104, 116, 116, 112, 58,
          47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 55, 48, 48,
          49, 13, 10, 83, 101, 99, 45, 87, 101, 98, 83, 111, 99, 107, 101, 116,
          45, 75, 101, 121, 49, 58, 32, 49, 57, 32, 111, 49, 55, 32, 54, 50,
          32, 52, 32, 53, 50, 13, 10, 83, 101, 99, 45, 87, 101, 98, 83, 111,
          99, 107, 101, 116, 45, 75, 101, 121, 50, 58, 32, 79, 52, 32, 48, 97,
          103, 39, 53, 121, 57, 32, 32, 72, 32, 54, 60, 32, 54, 101, 32, 57,
          49, 50, 13, 10, 13, 10,
          # these bytes are the upgrade data:
          241, 188, 139, 76, 196, 155, 103, 64 ]

string = bytes.pack('C*')
parser = Http::Parser.new

parser << string
p [parser.upgrade?, parser.upgrade_data.bytes.to_a]

This script prints the correct upgrade data on MRI, but not on JRuby:

$ rbenv shell 1.9.3-p392 
$ ruby hixie_76.rb 
[true, [241, 188, 139, 76, 196, 155, 103, 64]]

$ rbenv shell jruby-1.7.2 
$ ruby hixie_76.rb 
[true, [239, 191, 189, 76, 196, 155, 103, 64]]

@jcoglan
Copy link
Collaborator

jcoglan commented Mar 19, 2013

I've filed a bug with Http::Parser: tmm1/http_parser.rb#23

@samflores
Copy link
Author

Thanks a lot! ❤️

@jcoglan
Copy link
Collaborator

jcoglan commented May 5, 2013

I'm closing this issue since the bug has been shown to originate in another library. Please let me know if this proves counterproductive and we need to work around the bug in this library.

@jcoglan jcoglan closed this as completed May 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants