Message ID | 20241031120015.3651707-1-jose.quaresma@foundries.io |
---|---|
State | New |
Headers | show |
Series | [1/2] bitbake: hashserv: client: immediately test the server address | expand |
On Thu, 2024-10-31 at 12:00 +0000, Jose Quaresma via lists.openembedded.org wrote: > Test as soon as possible if it is possible to connect to the server > and use raw socket for this, which is much simpler and works for what you want. > > Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io> > --- > bitbake/lib/hashserv/__init__.py | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py > index ac891e0174..47b25fa6ab 100644 > --- a/bitbake/lib/hashserv/__init__.py > +++ b/bitbake/lib/hashserv/__init__.py > @@ -82,6 +82,15 @@ def create_client(addr, username=None, password=None): > c.connect_websocket(*a) > else: > c.connect_tcp(*a) > + > + # test the connection now > + import socket > + try: > + sock = socket.create_connection(a, timeout=5) > + sock.close() > + except socket.error as e: > + raise ConnectionError > + > return c > except Exception as e: > c.close() This didn't work, see below. Copying Joshua for comment on these. ERROR: Running idle function Traceback (most recent call last): File "/usr/lib/python3.11/contextlib.py", line 137, in _GeneratorContextManager.__enter__(): try: > return next(self.gen) except StopIteration: File "/mnt/b/yoe/master/sources/poky/bitbake/lib/bb/siggen.py", line 589, in SignatureGeneratorOEEquivHash.client(): if getattr(self, '_client', None) is None: > self._client = hashserv.create_client(self.server, **self.get_hashserv_creds()) yield self._client File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", line 97, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', username=None, password=None): c.close() > raise e File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", line 89, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', username=None, password=None): try: > sock = socket.create_connection(a, timeout=5) sock.close() File "/usr/lib/python3.11/socket.py", line 825, in create_connection(address=('/mnt/b/yoe/master/hashserve.sock',), timeout=5, source_address=None, all_errors=False): > host, port = address exceptions = [] ValueError: not enough values to unpack (expected 2, got 1) Cheers, Richard
I don't have the code in front of me, but this is almost certainly because the websockets and TCP sockets take different address types. IIRC TCP uses a tuple of (address, port), while websockets takes a URL. As such, I don't think you can use create_connection for both. On Sat, Nov 2, 2024, 8:14 AM Richard Purdie < richard.purdie@linuxfoundation.org> wrote: > On Thu, 2024-10-31 at 12:00 +0000, Jose Quaresma via > lists.openembedded.org wrote: > > Test as soon as possible if it is possible to connect to the server > > and use raw socket for this, which is much simpler and works for what > you want. > > > > Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io> > > --- > > bitbake/lib/hashserv/__init__.py | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/bitbake/lib/hashserv/__init__.py > b/bitbake/lib/hashserv/__init__.py > > index ac891e0174..47b25fa6ab 100644 > > --- a/bitbake/lib/hashserv/__init__.py > > +++ b/bitbake/lib/hashserv/__init__.py > > @@ -82,6 +82,15 @@ def create_client(addr, username=None, password=None): > > c.connect_websocket(*a) > > else: > > c.connect_tcp(*a) > > + > > + # test the connection now > > + import socket > > + try: > > + sock = socket.create_connection(a, timeout=5) > > + sock.close() > > + except socket.error as e: > > + raise ConnectionError > > + > > return c > > except Exception as e: > > c.close() > > This didn't work, see below. Copying Joshua for comment on these. > > ERROR: Running idle function > Traceback (most recent call last): > File "/usr/lib/python3.11/contextlib.py", line 137, in > _GeneratorContextManager.__enter__(): > try: > > return next(self.gen) > except StopIteration: > File "/mnt/b/yoe/master/sources/poky/bitbake/lib/bb/siggen.py", line > 589, in SignatureGeneratorOEEquivHash.client(): > if getattr(self, '_client', None) is None: > > self._client = hashserv.create_client(self.server, > **self.get_hashserv_creds()) > yield self._client > File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", > line 97, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', > username=None, password=None): > c.close() > > raise e > > File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", > line 89, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', > username=None, password=None): > try: > > sock = socket.create_connection(a, timeout=5) > sock.close() > File "/usr/lib/python3.11/socket.py", line 825, in > create_connection(address=('/mnt/b/yoe/master/hashserve.sock',), timeout=5, > source_address=None, all_errors=False): > > > host, port = address > exceptions = [] > ValueError: not enough values to unpack (expected 2, got 1) > > > Cheers, > > Richard > >
Joshua Watt <jpewhacker@gmail.com> escreveu (sábado, 2/11/2024 à(s) 15:55): > I don't have the code in front of me, but this is almost certainly because > the websockets and TCP sockets take different address types. IIRC TCP uses > a tuple of (address, port), while websockets takes a URL. As such, I don't > think you can use create_connection for both. > To be fair I only debugged and tested on the raw tests which were the ones that were failing. I hope to get back to this quickly. Jose > > On Sat, Nov 2, 2024, 8:14 AM Richard Purdie < > richard.purdie@linuxfoundation.org> wrote: > >> On Thu, 2024-10-31 at 12:00 +0000, Jose Quaresma via >> lists.openembedded.org wrote: >> > Test as soon as possible if it is possible to connect to the server >> > and use raw socket for this, which is much simpler and works for what >> you want. >> > >> > Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io> >> > --- >> > bitbake/lib/hashserv/__init__.py | 9 +++++++++ >> > 1 file changed, 9 insertions(+) >> > >> > diff --git a/bitbake/lib/hashserv/__init__.py >> b/bitbake/lib/hashserv/__init__.py >> > index ac891e0174..47b25fa6ab 100644 >> > --- a/bitbake/lib/hashserv/__init__.py >> > +++ b/bitbake/lib/hashserv/__init__.py >> > @@ -82,6 +82,15 @@ def create_client(addr, username=None, >> password=None): >> > c.connect_websocket(*a) >> > else: >> > c.connect_tcp(*a) >> > + >> > + # test the connection now >> > + import socket >> > + try: >> > + sock = socket.create_connection(a, timeout=5) >> > + sock.close() >> > + except socket.error as e: >> > + raise ConnectionError >> > + >> > return c >> > except Exception as e: >> > c.close() >> >> This didn't work, see below. Copying Joshua for comment on these. >> >> ERROR: Running idle function >> Traceback (most recent call last): >> File "/usr/lib/python3.11/contextlib.py", line 137, in >> _GeneratorContextManager.__enter__(): >> try: >> > return next(self.gen) >> except StopIteration: >> File "/mnt/b/yoe/master/sources/poky/bitbake/lib/bb/siggen.py", line >> 589, in SignatureGeneratorOEEquivHash.client(): >> if getattr(self, '_client', None) is None: >> > self._client = hashserv.create_client(self.server, >> **self.get_hashserv_creds()) >> yield self._client >> File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", >> line 97, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', >> username=None, password=None): >> c.close() >> > raise e >> >> File "/mnt/b/yoe/master/sources/poky/bitbake/lib/hashserv/__init__.py", >> line 89, in create_client(addr='unix:///mnt/b/yoe/master/hashserve.sock', >> username=None, password=None): >> try: >> > sock = socket.create_connection(a, timeout=5) >> sock.close() >> File "/usr/lib/python3.11/socket.py", line 825, in >> create_connection(address=('/mnt/b/yoe/master/hashserve.sock',), timeout=5, >> source_address=None, all_errors=False): >> >> > host, port = address >> exceptions = [] >> ValueError: not enough values to unpack (expected 2, got 1) >> >> >> Cheers, >> >> Richard >> >>
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py index ac891e0174..47b25fa6ab 100644 --- a/bitbake/lib/hashserv/__init__.py +++ b/bitbake/lib/hashserv/__init__.py @@ -82,6 +82,15 @@ def create_client(addr, username=None, password=None): c.connect_websocket(*a) else: c.connect_tcp(*a) + + # test the connection now + import socket + try: + sock = socket.create_connection(a, timeout=5) + sock.close() + except socket.error as e: + raise ConnectionError + return c except Exception as e: c.close()
Test as soon as possible if it is possible to connect to the server and use raw socket for this, which is much simpler and works for what you want. Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io> --- bitbake/lib/hashserv/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+)