10

I have Django + mod_wsgi + Apache server. I need to change default HTTP connection timeout. There is Timeout directive in apache config but it's not working.

How can I set this up?

3
  • for logout you can use: SESSION_COOKIE_AGE Commented Feb 12, 2014 at 18:30
  • You are going to have to explain better what the original problem is you are having so we can deduce what is needed. Right now it seems you have guessed on a solution and are trying to understand how to get that working, but without knowing the problem you are trying to solve the question doesn't make a great deal of sense. Commented Feb 12, 2014 at 22:33
  • 1
    When I issue HTTP GET Request to server after 60s there is a timeout (504 Gateway Timeout). I need a way to change this to some other value i.e. 120s. There is Timeout directive on Apache settings but that doesn't work. I don't know is this django or mod_wsgi or apache settings I need to change. Commented Feb 13, 2014 at 21:12

2 Answers 2

1

I solved this problem with:

python manage.py runserver --http_timeout 120

Sign up to request clarification or add additional context in comments.

2 Comments

This answer has got nothing to do with the question. They were not using the Django development server. They were using Apache/mod_wsgi.
Hey, I am using Django 3.0.3 version and when I pass --http_timeout option, I am getting error: recognized argument error. Any idea how to fix this error?
0

There is few timeout options in mod_wsgi WSGIDaemonProcess directive(check out request-timeout):

https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html

inactivity-timeout=sss (2.0+)

Defines the maximum number of seconds allowed to pass before the daemon process is shutdown and restarted when the daemon process has entered an idle state. For the purposes of this option, being idle means no new requests being received, or no attempts by current requests to read request content or generate response content for the defined period. This option exists to allow infrequently used applications running in a daemon process to be restarted, thus allowing memory being used to be reclaimed, with process size dropping back to the initial startup size before any application had been loaded or requests processed.

request-timeout=sss

Defines the maximum number of seconds that a request is allowed to run before the daemon process is restarted. This can be used to recover from a scenario where a request blocks indefinitely, and where if all request threads were consumed in this way, would result in the whole WSGI application process being blocked.

How this option is seen to behave is different depending on whether a daemon process uses only one thread, or more than one thread for handling requests, as set by the threads option.

If there is only a single thread, and so the process can only handle one request at a time, as soon as the timeout has passed, a restart of the process will be initiated.

If there is more than one thread, the request timeout is applied to the average running time for any requests, across all threads. This means that a request can run longer than the request timeout. This is done to reduce the possibility of interupting other running requests, and causing a user to see a failure. So where there is still capacity to handle more requests, restarting of the process will be delayed if possible.

deadlock-timeout=sss (2.0+)

Defines the maximum number of seconds allowed to pass before the daemon process is shutdown and restarted after a potential deadlock on the Python GIL has been detected. The default is 300 seconds. This option exists to combat the problem of a daemon process freezing as the result of a rouge Python C extension module which doesn't properly release the Python GIL when entering into a blocking or long running operation.

shutdown-timeout=sss

Defines the maximum number of seconds allowed to pass when waiting for a daemon process to gracefully shutdown as a result of the maximum number of requests or inactivity timeout being reached, or when a user initiated SIGINT signal is sent to a daemon process. When this timeout has been reached the daemon process will be forced to exited even if there are still active requests or it is still running Python exit functions. If this option is not defined, then the shutdown timeout will be set to 5 seconds. Note that this option does not change the shutdown timeout applied to daemon processes when Apache itself is being stopped or restarted. That timeout value is defined internally to Apache as 3 seconds and cannot be overridden.

...

Docs about WSGIDaemonProcess:

Using mod_wsgi daemon mode
Defining Process Groups

3 Comments

I think this will kill connection on timeout. I don't want that. I need to have connection open as long as django finish processing.
@ADRENALIN mm, didnt understand what you mean.. What you want to happen on server side when request process time exceeds timeout setting time?
I just want to extend server timeout from 60s to 120s. After 120s it is okay for timeout to occur.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.