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 committed Feb 4, 2019
1 parent 59b95e9 commit a230a55
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

0 comments on commit a230a55

Please sign in to comment.