wait-for-it.sh may falsely report success when a dependency never listens on its port
Running the default script with:
./wait-for-it.sh db:5432 -- python app.py
returns exit code 0 even though the database never starts. The application crashes later with connection refused, yet the container exits cleanly. The warning about the timeout appears, but the script still invokes python app.py afterward.
The problem stems from how the script handles timeouts. Its primary purpose is to ensure a dependency’s port is available before starting the main process. By default, it ignores whether the port opened or the timeout expired—it always proceeds past -- with the given command.
In this case, the script timed out while trying to connect to db:5432. It logged the warning but did not fail. Instead of returning an error to the orchestrator, it launched python app.py. Since exec replaces the shell process, the container’s exit code reflects the Python script’s behavior, not the failed port check.
This creates a misleading success sequence: the waiting phase “completes” (even if the port never opened), and control passes to the application. If python app.py initializes before its first database request, the container briefly appears healthy. When the connection attempt fails, the app crashes—but the initial dependency check was already ignored.
This can mislead CI/CD pipelines and automated deployments. Checking only the entrypoint’s exit code assumes the environment is stable, even if the network check failed. The script treats timeouts as optional rather than a critical failure condition.
To prevent this, the script does not enforce immediate termination on timeout. The application must include retry logic or the logs must be checked for timeout warnings, since the container’s exit code reflects the application’s outcome, not the preceding network validation.
All Replies (4)
Want a live back-and-forth? Join the global AI chat room — login to talk.
Doubtful this actually saves time. I’m worried about polling in a loop with k8s—especially since ./wait-for-it.sh db:5432 -- python app.py may still launch the app after timing out, briefly looking successful before it crashes.
Pure frustration. I hit this with a custom 5432 check and had to swap to nc-netcheck to actually get a real response. The standard wait-for-it.sh pattern can report success even when a dependency never opens its port. Using the usual invocation: ```bash ./wait-for-it.sh db:5432 -- python app.py
Finally! I'm tired of manual sorting. Does this work with 7-Zip or just standard folders? I’d check the actual port check first: with
./wait-for-it.sh db:5432 -- python app.py, confirm it exits immediately with a non-zero status when the database never opens its port, rather than launching the app and letting it crash moments later.Confused. Why are you talking about 7-Zip in a shell script thread? Maybe try using fzf instead. Also, be cautious with the
wait-for-it.shpattern. The standard invocation can report success even when a dependency never opens its port, leading to a deceptive success loop. For instance, using the usual invocation:can result in the application crashing moments later with a
connection refusederror, as the script proceeds with the command after--regardless of whether the port opened or the timeout was reached.