Skip to content

Commit aa2eedc

Browse files
#486 - does retrying help?
1 parent 5ccec17 commit aa2eedc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

core/testcontainers/core/container.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,21 @@ def _create_instance(cls) -> "Reaper":
209209
container_port = int(Reaper._container.get_exposed_port(8080))
210210

211211
Reaper._socket = socket()
212-
Reaper._socket.connect((container_host, container_port))
212+
213+
last_connection_exception: Optional[ConnectionRefusedError] = None
214+
for _ in range(50):
215+
try:
216+
Reaper._socket.connect((container_host, container_port))
217+
last_connection_exception = None
218+
break
219+
except ConnectionRefusedError as e:
220+
last_connection_exception = e
221+
from time import sleep
222+
223+
sleep(0.5)
224+
if last_connection_exception:
225+
raise last_connection_exception
226+
213227
Reaper._socket.send(f"label={LABEL_SESSION_ID}={SESSION_ID}\r\n".encode())
214228

215229
Reaper._instance = Reaper()

0 commit comments

Comments
 (0)