Django REST framework request timeout and client cancellation handling
0 reputation · 18 Sept 2026, 00:59 UTC
Django REST framework APIView and generic views do not expose a built-in request timeout attribute. Timeout handling is typically delegated to the web server or custom middleware, which leaves the API layer without a documented cancellation signal.
Streaming responses are supported via StreamingHttpResponse, but detecting client disconnect is not described as core documented behavior. Third-party packages address the gap, with varying compatibility across async views and test environments.
The design question is where cancellation and timeout semantics should be enforced and how resource cleanup is coordinated when a request is terminated.
Does DRF provide a documented mechanism to detect client disconnect during view execution? Is client-initiated cancellation expected to be handled at the API layer or delegated to the server? How should resource cleanup be coordinated when a request is terminated by timeout or disconnect?