Skip to content

Commit cd0a106

Browse files
committed
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).
1 parent 9946363 commit cd0a106

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reaper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ func reuseOrCreateReaper(ctx context.Context, sessionID string, provider ReaperP
170170
if err != nil {
171171
return nil, err
172172
}
173+
174+
Logger.Printf("⏳ Waiting for Reaper port to be ready")
175+
176+
var containerJson *types.ContainerJSON
177+
178+
if containerJson, err = reaperContainer.Inspect(ctx); err != nil {
179+
return nil, fmt.Errorf("failed to inspect reaper container %s: %w", reaperContainer.ID[:8], err)
180+
}
181+
182+
if containerJson != nil && containerJson.NetworkSettings != nil {
183+
for port := range containerJson.NetworkSettings.Ports {
184+
err := wait.ForListeningPort(port).
185+
WithPollInterval(100*time.Millisecond).
186+
WaitUntilReady(ctx, reaperContainer)
187+
if err != nil {
188+
return nil, fmt.Errorf("failed waiting for reaper container %s port %s/%s to be ready: %w",
189+
reaperContainer.ID[:8], port.Proto(), port.Port(), err)
190+
}
191+
}
192+
}
193+
173194
return reaperInstance, nil
174195
}
175196

0 commit comments

Comments
 (0)