Skip to content

Commit

Permalink
fix(core): #486 for colima delay for port avail for connect (#543)
Browse files Browse the repository at this point in the history
fix #486
  • Loading branch information
alexanderankin authored Apr 17, 2024
1 parent 8073874 commit 90bb780
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,26 @@ def _create_instance(cls) -> "Reaper":
container_host = Reaper._container.get_container_host_ip()
container_port = int(Reaper._container.get_exposed_port(8080))

Reaper._socket = socket()
Reaper._socket.connect((container_host, container_port))
last_connection_exception: Optional[Exception] = None
for _ in range(50):
try:
Reaper._socket = socket()
Reaper._socket.connect((container_host, container_port))
last_connection_exception = None
break
except (ConnectionRefusedError, OSError) as e:
if Reaper._socket is not None:
with contextlib.suppress(Exception):
Reaper._socket.close()
Reaper._socket = None
last_connection_exception = e

from time import sleep

sleep(0.5)
if last_connection_exception:
raise last_connection_exception

Reaper._socket.send(f"label={LABEL_SESSION_ID}={SESSION_ID}\r\n".encode())

Reaper._instance = Reaper()
Expand Down

0 comments on commit 90bb780

Please sign in to comment.