Add fetch2 wget exception handler
cover Add fetch2 wget exception handler
While rare we were getting TimeoutError exceptions in our CI infrastructure. It is unclear what the cause is (still being investigated), but from what I can tell, it appears connection opens, we do a number of invalid requests and the remote side just drops further requests (not closing the connection) which results in a socket TimeoutError.
Backtrace we receieved follows:
Checking sstate mirror object availability...ERROR: SState: cannot test file://13/8b/sstate:base-passwd:cortexa72-cortexa53-xilinx-linux:3.5.52:r0:cortexa72-cortexa53:10:138b29e1fe5981198dbca2fecdef5712826e63f2593e4d604ef54d6d5d51bd6d_package.tar.zst: TimeoutError('timed out') Traceback (most recent call last):
File "/poky/meta/classes-global/sstate.bbclass", line 1010, in checkstatus
fetcher.checkstatus()
File "/poky/bitbake/lib/bb/fetch2/__init__.py", line 1833, in checkstatus
ret = m.try_mirrors(self, ud, self.d, mirrors, True)
File "/poky/bitbake/lib/bb/fetch2/__init__.py", line 1606, in try_mirrors
return bool(try_mirrors(fetch, d, urldata, mirrors, check))
File "/poky/bitbake/lib/bb/fetch2/__init__.py", line 1134, in try_mirrors
ret = try_mirror_url(fetch, origud, uds[index], ld, check)
File "/poky/bitbake/lib/bb/fetch2/__init__.py", line 1027, in try_mirror_url
found = ud.method.checkstatus(fetch, ud, ld)
File "/poky/bitbake/lib/bb/fetch2/wget.py", line 369, in checkstatus
with opener.open(r, timeout=30) as response:
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/poky/bitbake/lib/bb/fetch2/wget.py", line 174, in http_open
return self.do_open(HTTPConnectionCache, req)
File "/poky/bitbake/lib/bb/fetch2/wget.py", line 244, in do_open
r = h.getresponse()
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/http/client.py", line 1374, in getresponse
response.begin()
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/http/client.py", line 318, in begin
version, status, reason = self._read_status()
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/http/client.py", line 279, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.10/socket.py", line 705, in readinto
return self._sock.recv_into(b)
TimeoutError: timed out
Mark Hatle (2):
wget.py: Add catch TimeoutError exception
wget.py: Combine urlopener exceptions
bitbake/lib/bb/fetch2/wget.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 wget.py: Add catch TimeoutError exception
We've observed TimeoutError exceptions during the sstate-cache mirror fetch, it appears that due to the number of (invalid) files requested the remote side is eventually dropping the connection (not closing it) which can result in a TimeoutError exception being sent, while rate it is different from the urllib.error.URLError or ConnectionResetError.
--- bitbake/lib/bb/fetch2/wget.py | 8 ++++++++ 1 file changed, 8 insertions(+)
bitbake/lib/bb/fetch2/wget.py +8 -0
@@ -385,6 +385,14 @@ class Wget(FetchMethod): # debug for now to avoid spamming the logs in e.g. remote sstate searches logger.debug2("checkstatus() urlopen failed: %s" % e) return False + except TimeoutError as e: + if try_again: + logger.debug2("checkstatus: trying again") + return self.checkstatus(fetch, ud, d, False) + else: + # debug for now to avoid spamming the logs in e.g. remote sstate searches + logger.debug2("checkstatus() urlopen TimeoutError: %s" % e) + return False return True
Signature · 1 line
2.25.1
PATCH 2/2 wget.py: Combine urlopener exceptions
In reply to Mark HatleNo reason to have three identical exception handles, refactor to catch any of the exceptions with the same block of code.
--- bitbake/lib/bb/fetch2/wget.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
bitbake/lib/bb/fetch2/wget.py +1 -17
@@ -369,7 +369,7 @@ class Wget(FetchMethod): with opener.open(r, timeout=30) as response: pass - except urllib.error.URLError as e: + except (urllib.error.URLError, ConnectionResetError, TimeoutError) as e: if try_again: logger.debug2("checkstatus: trying again") return self.checkstatus(fetch, ud, d, False)
@@ -377,22 +377,6 @@ class Wget(FetchMethod): # debug for now to avoid spamming the logs in e.g. remote sstate searches logger.debug2("checkstatus() urlopen failed: %s" % e) return False - except ConnectionResetError as e: - if try_again: - logger.debug2("checkstatus: trying again") - return self.checkstatus(fetch, ud, d, False) - else: - # debug for now to avoid spamming the logs in e.g. remote sstate searches - logger.debug2("checkstatus() urlopen failed: %s" % e) - return False - except TimeoutError as e: - if try_again: - logger.debug2("checkstatus: trying again") - return self.checkstatus(fetch, ud, d, False) - else: - # debug for now to avoid spamming the logs in e.g. remote sstate searches - logger.debug2("checkstatus() urlopen TimeoutError: %s" % e) - return False return True
Signature · 1 line
2.25.1