Skip to content

Commit 14e09fb

Browse files
committed
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
1 parent 1502552 commit 14e09fb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: lib/net/http.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,12 @@ def do_start
973973
private :do_start
974974

975975
def connect
976+
if use_ssl?
977+
# reference early to load OpenSSL before connecting,
978+
# as OpenSSL may take time to load.
979+
@ssl_context = OpenSSL::SSL::SSLContext.new
980+
end
981+
976982
if proxy? then
977983
conn_addr = proxy_address
978984
conn_port = proxy_port
@@ -1020,7 +1026,6 @@ def connect
10201026
end
10211027
end
10221028
end
1023-
@ssl_context = OpenSSL::SSL::SSLContext.new
10241029
@ssl_context.set_params(ssl_parameters)
10251030
@ssl_context.session_cache_mode =
10261031
OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |

0 commit comments

Comments
 (0)