From cd0a10616a9d4a0e35ef13dc3f2856fe5a4e332b Mon Sep 17 00:00:00 2001 From: esm Date: Sun, 19 May 2024 15:57:30 -0400 Subject: [PATCH] Wait for the ryuk port to be available in case the container is still being started by newReaper in a separate process. A race between newReaper and lookUpReaperContainer occurs: - newReaper creates the container with a ContainerRequest.WaitingFor = wait.ForListeningPort(listeningPort) - newReaper starts the container - lookUpReaperContainer obtains the container and returns. - newReaper invokes the readiness hook wait.ForListeningPort(listeningPort). --- reaper.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/reaper.go b/reaper.go index 4f288ed48d1..cd1c8ba0c97 100644 --- a/reaper.go +++ b/reaper.go @@ -170,6 +170,27 @@ func reuseOrCreateReaper(ctx context.Context, sessionID string, provider ReaperP if err != nil { return nil, err } + + Logger.Printf("⏳ Waiting for Reaper port to be ready") + + var containerJson *types.ContainerJSON + + if containerJson, err = reaperContainer.Inspect(ctx); err != nil { + return nil, fmt.Errorf("failed to inspect reaper container %s: %w", reaperContainer.ID[:8], err) + } + + if containerJson != nil && containerJson.NetworkSettings != nil { + for port := range containerJson.NetworkSettings.Ports { + err := wait.ForListeningPort(port). + WithPollInterval(100*time.Millisecond). + WaitUntilReady(ctx, reaperContainer) + if err != nil { + return nil, fmt.Errorf("failed waiting for reaper container %s port %s/%s to be ready: %w", + reaperContainer.ID[:8], port.Proto(), port.Port(), err) + } + } + } + return reaperInstance, nil }