Wait-for-db periodically fails on startup #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depending upon the timing of the container startup, the
wait-for-dbcommand may produce false positives, i.e., it will think the database is ready when it is not. In fact, I think the current implementation of wait-for-db does not work -- it only gets lucky. The connection object is lazy and must be used in order to produce theOperationalErrorexception. This PR calls out for a cursor object, which reliably tests that the database is functional.Steps to Reproduce:
You can reproduce this pretty reliably by repeating the following steps a few times:
docker system prunewill delete any cached containers (in a stopped state). In this case, the app container will sometimes start before the db container, yielding the error below. Notice in the log trace that the app_1 container is spinning up at the same time as the database and produces a false positive:Full stack trace for false positive: