Opened 3 weeks ago

Last modified 3 weeks ago

#28835 new Bug

Development server doesn't shut down on SIGTERM

Reported by: Slavek Kabrda Owned by: nobody
Component: Core (Management commands) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Hi, I've already opened a PR to fix this [1], but have been notified in a comment that I'll need to open a Trac ticket, so here it is. The explanation of this issue is at [1], but I'll C&P it here as well for clarity:

I've run into an issue where shutting down django devserver in a container (e.g. in kubernetes/openshift environment) doesn't work well. The original report is at [2].


  • kubernetes/openshift send SIGTERM to PID 1 in the container when shutting the container down.
  • If runserver is an entrypoint, it gets executed as PID 1 in container.
  • Linux kernel won't propagate SIGTERM to any process that is PID 1 (in or outside of container) if it doesn't have a handler installed for this signal.

The implication of this is that the container with django devserver will not do "soft" shutdown on SIGTERM and Kubernetes/Openshift will wait for timeout and kill the container with SIGKILL. Therefore the container will keep hanging and occupying system resources during the whole timeout.

Even though I understand that people should only use devserver for development and not for deployment, I think it's quite common to first make the container working with devserver for development and then consider Gunicorn or similar solution when moving from early stage of the project. IOW, I think this would really be beneficial for people using Kubernetes like environments to develop/deploy Django apps.

Thanks for considering!


Change History (4)

comment:1 Changed 3 weeks ago by Claude Paroz

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 3 weeks ago by Slavek Kabrda

I amended the PR with tests, so I believe it's now ready for review. PR

comment:3 Changed 3 weeks ago by Claude Paroz

Needs tests: unset
Patch needs improvement: set

Please uncheck Patch needs improvement when the Windows issue is solved.

comment:4 Changed 3 weeks ago by Slavek Kabrda

Patch needs improvement: unset

I marked the test to be skipped on Windows, as I believe this is actually not (easily) achievable on Windows. The Windows behavior is unaffected by my patch. All tests pass now, I'm unchecking "Patch needs improvement".

Note: See TracTickets for help on using tickets.
Back to Top