File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -221,8 +221,26 @@ def _create_instance(cls) -> "Reaper":
221221 container_host = Reaper ._container .get_container_host_ip ()
222222 container_port = int (Reaper ._container .get_exposed_port (8080 ))
223223
224- Reaper ._socket = socket ()
225- Reaper ._socket .connect ((container_host , container_port ))
224+ last_connection_exception : Optional [Exception ] = None
225+ for _ in range (50 ):
226+ try :
227+ Reaper ._socket = socket ()
228+ Reaper ._socket .connect ((container_host , container_port ))
229+ last_connection_exception = None
230+ break
231+ except (ConnectionRefusedError , OSError ) as e :
232+ if Reaper ._socket is not None :
233+ with contextlib .suppress (Exception ):
234+ Reaper ._socket .close ()
235+ Reaper ._socket = None
236+ last_connection_exception = e
237+
238+ from time import sleep
239+
240+ sleep (0.5 )
241+ if last_connection_exception :
242+ raise last_connection_exception
243+
226244 Reaper ._socket .send (f"label={ LABEL_SESSION_ID } ={ SESSION_ID } \r \n " .encode ())
227245
228246 Reaper ._instance = Reaper ()
You can’t perform that action at this time.
0 commit comments