kr8s-org / kr8s

A batteries-included Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl
https://kr8s.org
BSD 3-Clause "New" or "Revised" License
784 stars 41 forks source link

test_multiple_bind_addresses_port_forward appears to hang and fails (Macbook M3) #380

Open marcodlk opened 3 months ago

marcodlk commented 3 months ago

Which project are you reporting a bug for?

kr8s

What happened?

I've been running pytest kr8s/tests -k "not test_multiple_bind_addresses_port_forward" to test because that test function appears to hang and eventually fails. I am on a Macbook M3.

❯ uname -a
Darwin laptop-D96560.home 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031 arm64

Anything else?

No response

jacobtomlinson commented 3 months ago

I am able to reproduce this on my M3 MacBook (I typically develop kr8s on a Ubuntu machine though).

future: <Task finished name='Task-55' coro=<PortForward.start.<locals>.f() done, defined at /Users/jtomlinson/Projects/kr8s-org/kr8s/kr8s/_portforward.py:122> exception=OSError("could not bind on any address out of [('127.0.0.2', 28235)]")>
Traceback (most recent call last):
  File "/Users/jtomlinson/Projects/kr8s-org/kr8s/kr8s/_portforward.py", line 124, in f
    async with self as port:
  File "/Users/jtomlinson/Projects/kr8s-org/kr8s/kr8s/_portforward.py", line 112, in __aenter__
    return await self._run_task.__aenter__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jtomlinson/miniconda3/envs/kr8s/lib/python3.11/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jtomlinson/Projects/kr8s-org/kr8s/kr8s/_portforward.py", line 159, in _run
    server = await asyncio.start_server(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jtomlinson/miniconda3/envs/kr8s/lib/python3.11/asyncio/streams.py", line 84, in start_server
    return await loop.create_server(factory, host, port, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jtomlinson/miniconda3/envs/kr8s/lib/python3.11/asyncio/base_events.py", line 1539, in create_server
    raise OSError('could not bind on any address out of %r'
OSError: could not bind on any address out of [('127.0.0.2', 28235)]

We don't actually test Windows or Mac in CI so we can't really guarentee support. But I'd like to change that so I've opened #382 to track adding this.

Given this particular error happens when starting an asyncio server I suspect this error will either go away or change once #333 has been implemented. Therefore I suggest we prioritise that issue and then come back here once it is done and see what state things are in.

In the meantime we should probably just skip that test on Mac.