1

Background:

I have machine to machine communication system, where client is sending every now and then data to Apache Server. Communication is slow as mobile 2G is used for communication. Apache uses mod_wsgi (for Django).

Because client doesn't know actual data amount when communication is started, chunked transfer encoding is used between client and server. Because mod_wsgi doesn't support chunked transfer encoding, I'm using mod_proxy, which receives chunks and pass them as a single request to mod_wsgi with added content lenght information when all data has been received.

Problem:

I updated Ubuntu on server from 16.04 to 18.04 and after that some communication between client and server started to fail. From Apache's access.log I can see, that server responses 408 to client with "large" data. Large means in this context data amount needing something like 60 seconds for transfer. Nothing has changed on client side.

I have learnt that for Apache 2.4 (which I have on server's Ubuntu 18.04) TimeOut is 60 seconds, for earlier Apache version it was 300. I guess this is the reason for communication fails with new server OS in case of "large" data.

Side note:

I have noticed that enabling of mod_security solves the problem (no 408 with "large" data), but just when I disable mod_security and restart Apache, 408 returns to picture. security.conf have nothing related to timeout in it.

Question:

How to increase TimeOut correctly?

Tried so far:

As Apache really isn't my core competence, I have been trying to increase Timeout to some places (tried also KeepAliveTimeout even I think it's not correct way):

apache.conf snippet:

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 300

example.com.conf snippet:

ProxyRequests Off
ProxyTimeout 300

<Proxy http://example.com:81>
        Order deny,allow
        Allow from all
</Proxy>

<VirtualHost *:80>
        SetEnv proxy-sendcl 1
        ProxyPass / http://example.com:81/ connectiontimeout=300 timeout=300
        ProxyTimeout 300
        ProxyPassReverse / http://example.com:81/
        ProxyPreserveHost On
        ProxyVia Full

        <Directory proxy:*>
                Order deny,allow
                Allow from all
        </Directory>
</VirtualHost>

Listen 81

<VirtualHost *:81>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName example.com

1 Answer 1

0

Are you sure the 408 error is due to Apache is taking too long to serve the request?

HTTP 408 is "Request Timeout". It occurs when the client connects but doesn't send any data before the timeout triggers. You can use the ReqTimeout module (https://httpd.apache.org/docs/2.4/mod/mod_reqtimeout.html) to increase the timeout before receiving the request. Please, keep in mind that by increasing the timeout, you will have more apache processes busy waiting from the client to drop or use the socket.

4
  • I assume 408 is due to Apache as nothing has changed on client side. I will give a try for ReqTimeout module!
    – Tumbelo
    Nov 3, 2020 at 10:05
  • Thank you @Jesús Ángel! ReqTimeout module was enabled automatically for Apache 2.4. This wasn't case for older Apache version. And ReqTimeout was causing the problem. I disabled ReqTimeout and everything works nicely now. Once again: thanks for leading me toward solution.
    – Tumbelo
    Nov 3, 2020 at 11:37
  • @Tumbelo can you please elaborate on what you mean by disabling ReqTimeout fixed the problem? Did you comment out mod_reqtimeout or unloaded the module? I am having the same issue and any help would be appreciated Dec 7, 2020 at 2:38
  • @hunterqtransam I simply disabled mod_reqtimeout with sudo a2dismod reqtimeout. It needs Apache restart for activation (=for unloading the module from active confic) after module disable: sudo service apache2 restart. Hopefully this helps or at least leads towards solution.
    – Tumbelo
    Dec 8, 2020 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .