nginx tries to allocate a huge number of memory and fails

Mauro Stettler mauro.stettler at gmail.com
Thu Aug 4 03:47:08 UTC 2011


hi

i'm having a strange case where nginx is trying to allocate some
really huge amount of memory. we created a new vhost on nginx to
provide an internal interface to flush the apc cache of php. in most
of the cases i can request this and get what i expected, only in
around 20% of the request nginx is trying to allocate a huge number of
memory and fails, so it returns 500 internal server error.

2011/08/04 05:14:00 [emerg] 41529#0: *89012062 malloc()
18446744073709545066 bytes failed (12: Cannot allocate memory),
client: 192.168.1.195, server: *.kaufmich.vpn, request: "GET
/web1/apc/flushApc.php HTTP/1.1", host: "static.kaufmich.vpn"



does anybody have an idea why that would happen? i thought this almost
has to be a bug because the amount of bytes it is trying to allocate
is just so huge it just cant be right.



# nginx -V
nginx version: nginx/0.7.65
built by gcc 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
configure arguments: --prefix=/usr/local/nginx-0.7.65
--without-http_ssi_module --without-http_userid_module
--without-http_geo_module --with-pcre=/tmp/pcre-8.02
--add-module=src/http/modules/ngx_cache_purge/

server {
        server_name *.kaufmich.vpn;

        access_log /var/log/nginx/deployment_interface/access.log;
        error_log /var/log/nginx/deployment_interface/error.log debug;

        set $doc_dir /var/www/kaufmich;
        set $script_dir $doc_dir;
        root $doc_dir;

        location / {

        if ($request_uri !~* /.+/.+/.+) {
                return 501;
        }

        if ($request_uri ~* /(.+)/(.+\.php)) {
                set $prod_server $1;
                set $action $2;
                set $script $3;
                set $parameters "";
                set $script_dir $doc_dir/$action;
        }


        if ($request_uri ~* /(.+)/(.+)/(.+\.php)) {
                set $prod_server $1;
                set $action $2;
                set $script $3;
                set $parameters "";
                set $script_dir $doc_dir/$action;
        }

        if ($request_uri ~* /(.+)/(.+)/(.+\.php)\?(.+)) {
                set $prod_server $1;
                set $action $2;
                set $script $3;
                set $parameters $4;
                set $script_dir $doc_dir/$action;
        }

        include fastcgi_params;
        fastcgi_connect_timeout         3;
        fastcgi_send_timeout            25;
        fastcgi_read_timeout            25;
        fastcgi_intercept_errors        on;
        fastcgi_param DOCUMENT_ROOT     $script_dir;
        fastcgi_param SCRIPT_NAME       $script;
        fastcgi_param SCRIPT_FILENAME   $script_dir/$script;
        fastcgi_param PATH_INFO         $parameters;
        fastcgi_param QUERY_STRING      $parameters;
        fastcgi_param REQUEST_URI       $request_uri;
        fastcgi_param REQUEST_METHOD    $request_method;
        fastcgi_param CONTENT_TYPE      $content_type;
        fastcgi_param CONTENT_LENGTH    $content_length;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param REMOTE_ADDR       $remote_addr;

        if ($prod_server = "web1") {
                fastcgi_pass web1.kaufmich.com.cgi;
                break;
        }
        if ($prod_server = "web2") {
                fastcgi_pass web2.kaufmich.com.cgi;
                break;
        }
        if ($prod_server = "web3") {
                fastcgi_pass web3.kaufmich.com.cgi;
                break;
        }

        # else

        return 501;

        }
}



More information about the nginx mailing list