diff --git a/lib/mongo/socket/ssl.rb b/lib/mongo/socket/ssl.rb index 7c6d0aeafd..a5eeffb0ad 100644 --- a/lib/mongo/socket/ssl.rb +++ b/lib/mongo/socket/ssl.rb @@ -54,10 +54,10 @@ class SSL < Socket # @since 2.0.0 def connect! Timeout.timeout(timeout, Error::SocketTimeoutError) do - @tcp_socket.connect(::Socket.pack_sockaddr_in(port, host)) + handle_errors { @tcp_socket.connect(::Socket.pack_sockaddr_in(port, host)) } @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, context) @socket.sync_close = true - @socket.connect + handle_errors { @socket.connect } verify_certificate!(@socket) self end diff --git a/lib/mongo/socket/tcp.rb b/lib/mongo/socket/tcp.rb index 311be83bcf..5db1d8f0ef 100644 --- a/lib/mongo/socket/tcp.rb +++ b/lib/mongo/socket/tcp.rb @@ -43,7 +43,7 @@ class TCP < Socket def connect! Timeout.timeout(timeout, Error::SocketTimeoutError) do socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) - socket.connect(::Socket.pack_sockaddr_in(port, host)) + handle_errors { socket.connect(::Socket.pack_sockaddr_in(port, host)) } self end end diff --git a/lib/mongo/socket/unix.rb b/lib/mongo/socket/unix.rb index 5bcde3e5f7..fd1278424f 100644 --- a/lib/mongo/socket/unix.rb +++ b/lib/mongo/socket/unix.rb @@ -39,7 +39,7 @@ class Unix < Socket # @since 2.0.0 def connect! Timeout.timeout(timeout, Error::SocketTimeoutError) do - socket.connect(path) + handle_errors { socket.connect(path) } self end end