[Bug]: WaitStrategyTarget Handles Multiple Ports Differently to Documentation

Aperta Adatta ai principianti
#12,196 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@suvvvv ci sta già lavorando.

Dal 1/12/2026.

  • #12197 di @suvvvv — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, java
Ambito
testing-qa

Direzione di ricerca

Inizia da WaitStrategyTarget.getLivenessCheckPortNumbers() e da come ordina le porte dei container mappati. Quindi esamina i test della strategia di attesa HTTP per i container con più porte esposte. Riproduci la selezione intermittente e verifica che la correzione punti sempre alla prima porta mappata, con un test di regressione che copre due porte esposte.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type/bug
Module

Core

Testcontainers version

2.0.5

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version
Client:        Podman Engine
Version:       6.2.1
API Version:   6.2.1
Go Version:    go1.27.4-X:nodwarf5
Git Commit:    3471162efb28760529d852706c493c29245def6d
Built:         Tue Nov 24 00:00:00 2026
Build Origin:  Fedora Project
OS/Arch:       linux/amd64
What happened?

I'm trying to write a test for an application that listens on two ports, one HTTP and one SMTP.

container = new GenericContainer(image)
                .withExposedPorts(8090, 8091)
                .withNetwork(network)
                .withNetworkAliases("archive")
                .waitingFor(Wait.forHttp("/").forStatusCode(200))
                .withStartupTimeout(Duration.ofSeconds(30))

https://java.testcontainers.org/features/startup_and_waits/ says that TestContainers will wait for the first mapped port to be listening on TCP (or run a HTTP healthcheck if one is defined), but I'm seeing my tests intermittently fail to start. From the logs, it seems like TestContainers is alternating between ports to run the test against, failing to start if 8091 gets selected.

Tracing this through, I think the cause is WaitStrategyTarget.getLivenessCheckPortNumbers(). The ports listening on the container are remapped into a Set meaning the order is unpredictable between JVM executions. HashSets are deterministic, but it still means you can get unlucky with which ports get exposed on the container meaning that the wrong one gets picked to healthcheck against.

Relevant log output
2026-12-01T12:07:47.006+0000 INFO /sweet_montalcini: Waiting for 30 seconds for URL: http://localhost:45447/ (where port 45447 maps to container port 8091)
Additional Information

No response

Lingua principale
Java
Stelle
8.8k
Fork
2k
Merge medio
2g 1h
PR unite (30g)
11

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-java

Tutte le issue di testcontainers/testcontainers-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.