jruby/jruby-ossl — Issue #20: SSL server sending non-utf8 data can hang with openssl
Author: bporterfield
Created: 2012-03-01 05:05:58+00:00
State: open

Not quite sure yet if this belongs here. Requests seem to hang over ssl when sending back data read from a file that isn't all utf-8. Over http it works, and the same app works in both cases in MRI.

Rack app:

require 'rack/utils'
require 'openssl'
require 'webrick'
require 'webrick/https'

class SslEncodingIssue
def call(env)

# file can be downloaded from https://gist.github.com/1947380
out = File.read("gistfile1.txt")

headers = {}
headers["Content-Length"] = [out].inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
headers["Content-Type"] = "text/html"

[200, headers, [out]]
end
end

pkey = OpenSSL::PKey::RSA.new(File.read("keypair.pem"))
cert = OpenSSL::X509::Certificate.new(File.read("cert.pem"))

Rack::Handler::WEBrick.run(
SslEncodingIssue.new,
:Port => 3000,
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => cert,
:SSLPrivateKey => pkey,
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ]
)

Run `rackup` and ping `http://localhost:3000/` - for me, the request hangs for a bit, and curl responds with: `* transfer closed with 2 bytes remaining to read`.

Change `:SSLEnable = true` to = `:SSLEnable = false` and hit the http url, and the problem goes away. I've put this test case into Webrick, but was having the same issue with other server.

Seems to be very dependent on length of output - remove a few lines on dots and the issue does not occur.

Happy to provide more info!