Skip to content

Commit

Permalink
Fix SSL_shutdown (#7372)
Browse files Browse the repository at this point in the history
* Add manual specs to perform https requests
* Assume connection is closed when ssl_shutdown reports syscall error
Based on d5fe700
* Cleanup unused code
  • Loading branch information
bcardiff authored Feb 4, 2019
1 parent 0ef090a commit b1abae7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
15 changes: 15 additions & 0 deletions spec/manual/https_client_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec"
require "openssl"
require "http"

describe "https requests" do
it "can fetch from google.com" do
HTTP::Client.get("https://google.com")
end

it "can close request before consuming body" do
HTTP::Client.get("https://crystal-lang.org") do
break
end
end
end
17 changes: 4 additions & 13 deletions src/openssl/ssl/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,14 @@ abstract class OpenSSL::SSL::Socket < IO
ret = LibSSL.ssl_shutdown(@ssl)
break if ret == 1
raise OpenSSL::SSL::Error.new(@ssl, ret, "SSL_shutdown") if ret < 0
rescue e : Errno
case e.errno
when 0
# OpenSSL claimed an underlying syscall failed, but that didn't set any error state,
# assume we're done
break
when Errno::EAGAIN
# Ignore/retry, shutdown did not complete yet
when Errno::EINPROGRESS
# Ignore/retry, another operation not complete yet
else
raise e
end
rescue e : OpenSSL::SSL::Error
case e.error
when .want_read?, .want_write?
# Ignore, shutdown did not complete yet
when .syscall?
# OpenSSL claimed an underlying syscall failed, but that didn't set any error state,
# assume we're done
break
else
raise e
end
Expand Down

1 comment on commit b1abae7

@rdp
Copy link
Contributor

@rdp rdp commented on b1abae7 Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me on ubuntu git master, with this spec I get:

$ ./bin/crystal spec/manual/https_client_spec.cr
Using compiled compiler at `.build/crystal'
.E

Failures:

  1) https requests can close request before consuming body

       SSL_shutdown: error:14094123:SSL routines:ssl3_read_bytes:application data after close notify (OpenSSL::SSL::Error)
         from src/openssl/ssl/socket.cr:158:11 in 'unbuffered_close'
         from src/io/buffered.cr:202:5 in 'close'
         from src/http/client.cr:742:19 in 'close'
         from spec/manual/https_client_spec.cr:251:7 in '->'
         from src/spec/example.cr:255:3 in 'run'
         from src/spec/context.cr:211:23 in 'run'
         from src/spec/context.cr:42:23 in 'run'
         from src/spec/dsl.cr:235:7 in '->'
         from src/kernel.cr:255:3 in 'run'
         from src/crystal/main.cr:47:5 in 'main'
         from src/crystal/main.cr:106:3 in 'main'
         from __libc_start_main
         from _start
         from ???
       

Finished in 672.92 milliseconds
2 examples, 0 failures, 1 errors, 0 pending

Failed examples:

crystal spec spec/manual/https_client_spec.cr:10 # https requests can close request before consuming body

FWIW ...

Please sign in to comment.