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 }