Skip to contentSkip to conversation

bitbake: checkstatus: drop shared connecton when catch Timeout error

PATCH New y75zhang 1 participant 1 message Jul 5, 2024

lore
Share & tools
lore

y75zhang

author
#0 lore raw

PATCH 1/1 bitbake: checkstatus: drop shared connecton when catch Timeout error

* to avoid wrong http response in checkstatus function:
in wget checkstatus() we are using 'HTTPConnectionCache' to share connections
1. state_file1(exists on http server) use shared connection <shared1> to send request
2. http_server recieved request of state_file1, but delayed by some reason to sent respone
3. state_file1 checkstatus() failed by timeout and drop shared connection <shared1>
4. state_file2(not exists on http server) get shared connection <shared1> and send request
5. http_server finally send 200 response for state_file1
6. state_file2 recived 200 response and thought it was exists on http_server

* how to reproduce:
modify /usr/lib64/python3.10/http/client.py like this to fake timeout event
you will find that some sstate files with 200 response in fact do not exists in remote http server
— a/client.py
+++ b/client.py
@@ -68,6 +68,7 @@ Req-started-unread-response _CS_REQ_STARTED <response_class>
Req-sent-unread-response _CS_REQ_SENT <response_class>
"""

+import random
import email.parser
import email.message
import errno
@@ -1370,6 +1371,8 @@ class HTTPConnection:
else:
response = self.response_class(self.sock, method=self._method)

+ if random.choice([False, False, False, False, False, False, False, True]):
+ raise TimeoutError('timed out test')
try:
try:
response.begin()

---
 bitbake/lib/bb/fetch2/wget.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
bitbake/lib/bb/fetch2/wget.py +7 -2
index 2e92117..56caf92 100644
@@ -244,7 +244,12 @@ class Wget(FetchMethod):
                         fetch.connection_cache.remove_connection(h.host, h.port)
                     raise urllib.error.URLError(err)
                 else:
-                    r = h.getresponse()
+                    try:
+                        r = h.getresponse()
+                    except TimeoutError as e:
+                        if fetch.connection_cache:
+                            fetch.connection_cache.remove_connection(h.host, h.port)
+                        raise TimeoutError(e)
 
                 # Pick apart the HTTPResponse object to get the addinfourl
                 # object initialized properly.
@@ -496,7 +501,7 @@ class Wget(FetchMethod):
                     valid = 1
                 elif self._vercmp(version, newver) < 0:
                     version = newver
-                
+
         pupver = re.sub('_', '.', version[1])
 
         bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %
Signature · 1 line
2.9.5