I was testing error handling with the ucscsdk, especially timeouts when logging in with a handle to UCSC instance. The following code should throw a timeout exception after the default timeout has been exceeded. However, only the first time a handle is being created and times out, the exception is being thrown. After that, further handles just hang forever at the login() method. Digging down the source, it seems that a lock is not released in ucscsession.py when a timeout (or connection refused, etc.) exception occurs (on line 250).
try:
handle = UcscHandle(self.creds['hostname'], self.creds['username'], self.creds['password']))
if handle.last_update_time is None:
handle.login()
except Exception as e:
print(e)
return
Traceback (most recent call last):
File "/mnt/hgfs/ucsc-exporter/modules/main_collector.py", line 100, in collect
self.handles[x].login()
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucschandle.py", line 117, in login
return self._login(auto_refresh, force)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscsession.py", line 475, in _login
response = self.post_elem(elem)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscsession.py", line 250, in post_elem
response_str = self.post_xml(xml_str, dme=dme)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscsession.py", line 203, in post_xml
response_str = self.post(uri=ucsm_uri, data=xml_str, read=read)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscsession.py", line 185, in post
response = self.__driver.post(uri=uri, data=data, read=read)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscdriver.py", line 180, in post
response = opener.open(request, timeout=10)
File "/usr/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/home/eric/.local/lib/python3.7/site-packages/ucscsdk/ucscdriver.py", line 42, in https_open
return self.do_open(TLS1Connection, req)
File "/usr/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error timed out>
ucscsdk version: 0.9.0.1
Python version: 3.7.3
Operating System: Debian 10
Description
I was testing error handling with the ucscsdk, especially timeouts when logging in with a handle to UCSC instance. The following code should throw a timeout exception after the default timeout has been exceeded. However, only the first time a handle is being created and times out, the exception is being thrown. After that, further handles just hang forever at the
login()method. Digging down the source, it seems that a lock is not released in ucscsession.py when a timeout (or connection refused, etc.) exception occurs (on line 250).What I Did
Minimal code:
Stacktrace of timeout