Skip to content

Commit fe1a930

Browse files
committed
RUBY-1101 SSL and Unix sockets are only connectable if they've been created
1 parent fac7e27 commit fe1a930

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

lib/mongo/server/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Connection
5656
#
5757
# @since 2.0.0
5858
def connect!
59-
unless socket
59+
unless socket && socket.connectable?
6060
@socket = address.socket(timeout, ssl_options)
6161
socket.connect!
6262
authenticate!

lib/mongo/socket/ssl.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def readbyte
9999
end
100100
end
101101

102+
# This socket can only be used if the ssl socket (@socket) has been created.
103+
#
104+
# @example Is the socket connectable?
105+
# socket.connectable?
106+
#
107+
# @return [ true, false ] If the socket is connectable.
108+
#
109+
# @since 2.2.5
110+
def connectable?
111+
!!@socket
112+
end
113+
102114
private
103115

104116
def create_context(options)

lib/mongo/socket/tcp.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ def initialize(host, port, timeout, family)
6464
@host, @port, @timeout = host, port, timeout
6565
super(family)
6666
end
67+
68+
# This object does not wrap another socket so it's always connectable.
69+
#
70+
# @example Is the socket connectable?
71+
# socket.connectable?
72+
#
73+
# @return [ true, false ] If the socket is connectable.
74+
#
75+
# @since 2.2.5
76+
def connectable?
77+
true
78+
end
6779
end
6880
end
6981
end

lib/mongo/socket/unix.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ def initialize(path, timeout)
5555
@socket = ::UNIXSocket.new(path)
5656
set_socket_options(@socket)
5757
end
58+
59+
# This socket can only be used if the unix socket (@socket) has been created.
60+
#
61+
# @example Is the socket connectable?
62+
# socket.connectable?
63+
#
64+
# @return [ true, false ] If the socket is connectable.
65+
#
66+
# @since 2.2.5
67+
def connectable?
68+
!!@socket
69+
end
5870
end
5971
end
6072
end

0 commit comments

Comments
 (0)