File tree 2 files changed +6
-4
lines changed
2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -112,10 +112,10 @@ def __init__(self,
112
112
"{}" .format (socket_dir ))
113
113
114
114
for _file in glob .glob (os .path .join (socket_dir , '*' )):
115
- if is_unix_socket (_file ) and connected_socket (_file ):
115
+ if is_unix_socket (_file ) and connected_socket (_file , timeout ):
116
116
socket_files .append (_file )
117
117
elif (socket_file and is_unix_socket (socket_file ) and
118
- connected_socket (socket_file )):
118
+ connected_socket (socket_file , timeout )):
119
119
socket_files .append (os .path .realpath (socket_file ))
120
120
else :
121
121
raise ValueError ("UNIX socket file was not set" )
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ def is_unix_socket(path):
158
158
159
159
return stat .S_ISSOCK (mode )
160
160
161
- def connected_socket (path ):
161
+ def connected_socket (path , timeout ):
162
162
"""Check if socket file is a valid HAProxy socket file.
163
163
164
164
We send a 'show info' command to the socket, build a dictionary structure
@@ -167,13 +167,15 @@ def connected_socket(path):
167
167
168
168
:param path: file name path
169
169
:type path: ``string``
170
+ :param timeout: timeout for the connection, in seconds
171
+ :type timeout: ``float``
170
172
:return: ``True`` is socket file is a valid HAProxy stats socket file False
171
173
otherwise
172
174
:rtype: ``bool``
173
175
"""
174
176
try :
175
177
unix_socket = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
176
- unix_socket .settimeout (0.1 )
178
+ unix_socket .settimeout (timeout )
177
179
unix_socket .connect (path )
178
180
unix_socket .send (six .b ('show info' + '\n ' ))
179
181
file_handle = unix_socket .makefile ()
You can’t perform that action at this time.
0 commit comments