-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
OpenSSL exception when reading/writing at line-rate #7456
Comments
This is a minimal example that reproduces the problem consistently: require "socket"
require "openssl"
def server
socket = TCPServer.new(5555)
context = OpenSSL::SSL::Context::Server.new
context.private_key = "localhost.key"
context.certificate_chain = "localhost.crt"
loop do
client = socket.accept? || break
ssl_socket = OpenSSL::SSL::Socket::Server.new(client, context, sync_close: true)
spawn echo(ssl_socket)
end
end
def echo(ssl_socket)
puts "Client connected"
i = 0
buf = uninitialized UInt8[4096]
loop do
i += 1
ssl_socket.read(buf.to_slice)
ssl_socket.write(buf.to_slice)
end
rescue ex
puts "Failed at the #{i} read"
raise ex
end
def client
socket = TCPSocket.new("127.0.0.1", 5555)
context = OpenSSL::SSL::Context::Client.new
context.verify_mode = OpenSSL::SSL::VerifyMode::NONE
ssl_socket = OpenSSL::SSL::Socket::Client.new(socket, context)
spawn do
buf = StaticArray(UInt8, 1000).new(0)
loop do
ssl_socket.write buf.to_slice
end
end
buf = uninitialized UInt8[4096]
loop do
ssl_socket.read buf.to_slice
end
end
unless File.exists? "localhost.key"
system "openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost'"
end
spawn client
server Output:
Now if you tweak the Curiously, if i decrease the |
Also noticed that if I disable write buffering on the client socket it doesn't crash either: ssl_socket = OpenSSL::SSL::Socket::Client.new(socket, context)
socket.sync = true
... Related to #7458 ? |
@carlhoerberg Could you add a spec to this in I tried to write it but I don't understand the code above well enough to put it in a spec. (Or if someone else wants to do it, please go ahead. Thank you!) |
When reading from a
OpenSSL::SSL::Socket::Server
at full speed I very quickly getHowever, if i phase the write side I don't get it.
Will add an example but opening the issue as an placeholder.
The text was updated successfully, but these errors were encountered: