timesketch-web
container crashes and restarts initially due to postgres race-condition
#3263
Labels
timesketch-web
container crashes and restarts initially due to postgres race-condition
#3263
Describe the bug
When starting the docker compose stack for the first time the
timesketch-web
container tries to create the database tables.During the initial startup multiple workers try to
CREATE TABLE
, which causes postgres to throw an error and thetimesketch-web
container crashes and restarts.wsgi_error.log
multiple workers are started
timesketch/docker/release/build/docker-entrypoint.sh
Lines 5 to 9 in 449c7fe
an app is created
timesketch/timesketch/wsgi.py
Line 46 in 449c7fe
which initializes the database
timesketch/timesketch/wsgi.py
Line 46 in 449c7fe
which calls
BaseModel.metadata.create_all
timesketch/timesketch/models/__init__.py
Line 55 in 449c7fe
Postgres errors, because concurrent
CREATE TABLE
statements aren't supported: https://www.postgresql.org/message-id/CA+TgmoZAdYVtwBfp1FL2sMZbiHCWT4UPrzRLNnX1Nb30Ku3-gg@mail.gmail.comEventually the table exists and
timesketch-web
continues to work as intended (with one or two restarts though).The problem I have with this issue, is that I'm trying to use
docker compose up -d --wait
with health checks, which should wait until all containers are ready. But because the container crashes it will be markedunhealthy
and this seems to be intended behavior with docker compose:To Reproduce
diff docker-compose.yml
Steps to reproduce the behavior:
deploy_timesketch.sh
scriptdiff docker-compose.yml
to include healthchecksdocker compose up -d --wait
docker ps
ordocker inspect timesketch-web | jq '.[] | .RestartCount'
wsgi_error.log
Expected behavior
The container should not crash.
Possible fixes
Call an additional python script that gets run from the
docker-entrypoint.sh
, before the gunicorn workers are started, to create the tables:timesketch/docker/release/build/docker-entrypoint.sh
Lines 3 to 5 in 449c7fe
Or: use
pg_advisory_lock
as described by the Posgres maintainers.Desktop (please complete the following information):
Additional context
Related: #3014 (comment)
The text was updated successfully, but these errors were encountered: