aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormohamed <mohamed.m.m.hafez@gmail.com>2021-02-15 09:36:50 -0800
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-04-28 10:47:29 +0900
commitff931d03366e7d07d4974d4bff51128ddbc5e1d6 (patch)
treeeb56ec51dc370b7308c411c5045a5747b5aa4115 /lib
parent4c8cce5b8a5eef73c08d26e17f6d0b55772131d6 (diff)
downloadruby-ff931d03366e7d07d4974d4bff51128ddbc5e1d6.tar.gz
[ruby/net-smtp] Replace Timeout.timeout with socket timeout
Timeout.timeout is inefficient since it spins up a new thread for each invocation, use Socket.tcp's connect_timeout option instead https://github.com/ruby/net-smtp/commit/6ae4a59f05
Diffstat (limited to 'lib')
-rw-r--r--lib/net/smtp.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 6ce20597ae..9dd1d26d22 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -588,7 +588,12 @@ module Net
private
def tcp_socket(address, port)
- TCPSocket.open address, port
+ begin
+ Socket.tcp address, port, nil, nil, connect_timeout: @open_timeout
+ rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
+ raise Net::OpenTimeout, "Timeout to open TCP connection to "\
+ "#{address}:#{port} (exceeds #{@open_timeout} seconds)"
+ end
end
def do_start(helo_domain, user, secret, authtype)
@@ -597,9 +602,7 @@ module Net
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
check_auth_args user, secret
end
- s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
- tcp_socket(@address, @port)
- end
+ s = tcp_socket(@address, @port)
logging "Connection opened: #{@address}:#{@port}"
@socket = new_internet_message_io(tls? ? tlsconnect(s, @ssl_context_tls) : s)
check_response critical { recv_response() }