Skip to content

Docker: Server process does not shut down gracefully #4767

@ledlamp

Description

@ledlamp

According to this code, there should be a graceful shutdown on SIGTERM, and "shutting down..." should appear in the log.

// Wait for signal to initiate server shutdown.
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
sig := <-quit
// Stop all background activity.
auto.Shutdown()
workers.Shutdown()
session.Shutdown()
mutex.CancelAll()
log.Info("shutting down...")
cancel()
if contextErr := dctx.Release(); contextErr != nil {
log.Error(contextErr)
}
// Finally, close the DB connection after a short grace period.
time.Sleep(2 * time.Second)
conf.Shutdown()
// Don't exit with 0 if SIGUSR1 was received to avoid restarts.
if sig == syscall.SIGUSR1 {
os.Exit(1)
return nil
}
return nil

Docker sends SIGTERM to the entrypoint process, but the process exits immediately with code 143, without any further log output.

One of the issues this causes is the unix socket is not removed on shutdown (#4673 (comment)). It might cause other issues as well.

I reproduced it with fresh Multipass VM with Ubuntu 24.04.1 (launch with more than 5gib disk). I installed docker with sudo apt install docker.io docker-compose. Docker version is 26.1.3. I used the official compose file from the documentation:

wget https://dl.photoprism.app/docker/compose.yaml

Without making any changes, I run it with docker-compose up -d, and it runs normally.

Image

Then I stop server with docker-compose stop photoprism.

In docker-compose logs photoprism, nothing is logged on shutdown.

In docker inspect photoprism_photoprism_1, the exit status is 143.

Image

According to this code, the exit status should be 1:

// Don't exit with 0 if SIGUSR1 was received to avoid restarts.
if sig == syscall.SIGUSR1 {
os.Exit(1)
return nil
}

because the docker entrypoint script traps SIGTERM and sends SIGUSR1 to photoprism:

trap "kill -USR1 $PID" INT TERM

Metadata

Metadata

Labels

bugSomething isn't workingdockerDocker Images, Build Scripts, Config & Deployment ExamplesreleasedAvailable in the stable release

Type

Projects

Status

Release 🌈

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions