From 0296a64450019bf0d2c5b342a1d988ca3ace3d66 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 27 Oct 2020 14:48:25 -0700 Subject: [PATCH] [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 --- lib/net/http.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 |