Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I terminate a long-running Django request if the XHR gets an abort()?

I initiate a request client-side, then I change my mind and call xhr.abort().

How does Django react to this? Does it terminate the thread somehow? If not, how do I get Django to stop wasting time trying to respond to the aborted request? How do I handle it gracefully?

like image 341
Scott Stafford Avatar asked Jun 30 '14 19:06

Scott Stafford


1 Answers

Due to how http works and that you usually got a frontend in front of your django gunicorn app processes (or uswgi etc), your http cancel request is buffered by nginx. The gunicorns don't get a signal, they just finish processing and then output whatever to the http socket. But if that socket is closed it will have an error (which is caught as a closed connection and move one).

So it's easy to DOS a server if you can find a way to spawn many of these requests.

But to answer your question it depends on the backend, with gunicorn it will keep going until the timeout.

like image 141
dalore Avatar answered Oct 15 '22 16:10

dalore