summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-10-27 14:48:25 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-04-28 11:03:12 +0900
commit0296a64450019bf0d2c5b342a1d988ca3ace3d66 (patch)
tree5c2b40b7ec1f5d18090568072f8df8146300e85c /lib/net
parent1229ad0528d28e38f031f1301e1c5331cfd03a90 (diff)
[ruby/net-http] Initialize OpenSSL early before creating TCPSocket
OpenSSL make take some time to initialize, and it would be best to take that time before connecting instead of after. From joshc on Redmine. Fixes Ruby Bug #9459 https://github.com/ruby/net-http/commit/14e09fba24
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/http.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 9351606215..862f88dd37 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -972,6 +972,12 @@ module Net #:nodoc:
private :do_start
def connect
+ if use_ssl?
+ # reference early to load OpenSSL before connecting,
+ # as OpenSSL may take time to load.
+ @ssl_context = OpenSSL::SSL::SSLContext.new
+ end
+
if proxy? then
conn_addr = proxy_address
conn_port = proxy_port
@@ -1018,7 +1024,6 @@ module Net #:nodoc:
end
end
end
- @ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.set_params(ssl_parameters)
@ssl_context.session_cache_mode =
OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |