comparison roundup/scripts/roundup_server.py @ 6834:5129fc03dc1f

issue2551137, 2551138 - roundup-server SSL issues. Python3 no longer supports socket._fileobject, so fake it using SocketIO and layering io.BufferedReader as in: https://bugs.launchpad.net/python-glanceclient/+bug/1812525 Also handle SSL.ZeroReturnError exception by ignoring it. This exception is thrown when the SSL layer has been closed and a read happens. There is a warning in openssl as well as python docs that the underlying (unencrypted) socket may not be closed. In manual testing, netstat -anp didn't show any unclosed socket so.... Could it leak a fd still, unknown. This also seesm to have fixed an error when running under python2 where socket shutdown throws an error. Maybe ignoring ZeroErrorREturn handled that case? Also added doc to man page recommending not using -s and using a real web server instead. Also added doc on format of pem file passed to -e. No automated testing on this, so no test updates 8-(.
author John Rouillard <rouilj@ieee.org>
date Thu, 18 Aug 2022 14:44:16 -0400
parents d659cfa8439c
children 8e4028669d2a
comparison
equal deleted inserted replaced
6833:da9a78957bd4 6834:5129fc03dc1f
159 while True: 159 while True:
160 try: 160 try:
161 return self.__fileobj.readline(*args) 161 return self.__fileobj.readline(*args)
162 except SSL.WantReadError: 162 except SSL.WantReadError:
163 time.sleep(.1) 163 time.sleep(.1)
164 except SSL.ZeroReturnError:
165 # Raised here on every request.
166 # SSL connection has been closed.
167 # But maybe not the underlying socket.
168 # FIXME: Does this lead to a socket leak??
169 # if so how to fix?
170 pass
164 171
165 def read(self, *args): 172 def read(self, *args):
166 """ SSL.Connection can return WantRead """ 173 """ SSL.Connection can return WantRead """
167 while True: 174 while True:
168 try: 175 try:
169 return self.__fileobj.read(*args) 176 return self.__fileobj.read(*args)
170 except SSL.WantReadError: 177 except SSL.WantReadError:
171 time.sleep(.1) 178 time.sleep(.1)
179 except SSL.ZeroReturnError:
180 # Put here to match readline() handling above.
181 # Even though this never was the source of the
182 # exception logged during use.
183 # SSL connection has been closed.
184 # But maybe not the underlying socket.
185 # FIXME: Does this lead to a socket leak??
186 # if so how to fix?
187 pass
172 188
173 def __getattr__(self, attrib): 189 def __getattr__(self, attrib):
174 return getattr(self.__fileobj, attrib) 190 return getattr(self.__fileobj, attrib)
175 191
176 class ConnFixer(object): 192 class ConnFixer(object):
178 which the HTTP handlers require """ 194 which the HTTP handlers require """
179 def __init__(self, conn): 195 def __init__(self, conn):
180 self.__conn = conn 196 self.__conn = conn
181 197
182 def makefile(self, mode, bufsize): 198 def makefile(self, mode, bufsize):
183 fo = socket._fileobject(self.__conn, mode, bufsize) 199 fo = None
184 return RetryingFile(fo) 200 try:
201 # see below of url used for this
202 fo = socket.SocketIO(self.__conn, mode)
203 except AttributeError:
204 # python 2 in use
205 buffer = socket._fileobject(self.__conn, mode, bufsize)
206
207 if fo:
208 # python3 set up buffering
209 # verify mode is rb and bufsize is -1
210 # implement subset of socket::makefile
211 # https://bugs.launchpad.net/python-glanceclient/+bug/1812525
212 if mode == 'rb' and bufsize == -1:
213 buffering = io.DEFAULT_BUFFER_SIZE
214 buffer = io.BufferedReader(fo, buffering)
215 else:
216 buffer = fo
217
218 return RetryingFile(buffer)
185 219
186 def __getattr__(self, attrib): 220 def __getattr__(self, attrib):
187 return getattr(self.__conn, attrib) 221 return getattr(self.__conn, attrib)
188 222
189 conn = ConnFixer(conn) 223 conn = ConnFixer(conn)

Roundup Issue Tracker: http://roundup-tracker.org/