We run a Django REST API behind Gunicorn (on a Kubernetes Cluster in EKS exposed via AWS ALB).
The Gunicorn command:
gunicorn config.wsgi --timeout 20 (...)
When a request takes over 20 seconds to be processed by Django (due to various reasons), gunicorn will timeout by emitting a SigAbt signal and restart the gunicorn worker.
However, this causes an issue in tracking the error in various tools such as Datadog or Sentry which are not able to track the error correctly.
Instead, we would like to emit an explicit error (customer error) called TimeoutError.
After a thorough investigation, we want to find the best way to raise this TimeoutError at Django Level when the request takes 20 seconds to complete.
What would be a recommended solution?
We added a configuration file to gunicorn:
in which we defined a Gunicorn Server Hook used to raise the exception:
Documentation: