Project

General

Profile

Bug #2894

Memory leak if two fcgi calls with one request (authentication and response)

Added by rschmid 21 days ago. Updated 21 days ago.

Status:
Patch Pending
Priority:
Normal
Assignee:
-
Category:
mod_fastcgi
Target version:
Start date:
2018-06-25
Due date:
% Done:

0%

Estimated time:
Missing in 1.5.x:

Description

Hello,

if lighttpd (1.4.49) is configured to authenticate via fcgi and also responds via a second fcgi (or the same fcgi), the memory grows slowly.
This is because in gw_backend.c the chunk queue is only reset after authentication and then newly initialized in mod_fastcgi.c. The reseted memory remains.
gw_backend.c (line 1117):

static void handler_ctx_clear(gw_handler_ctx *hctx) {
    /* caller MUST have called gw_backend_close(srv, hctx) if necessary */

    ...

    if (hctx->rb) chunkqueue_reset(hctx->rb);

    ...

}

mod_fastcgi.c (line 511)
static handler_t fcgi_check_extension(server *srv, connection *con, void *p_d, int uri_path_handler) {

    if (con->mode == p->id) {
        ...
        hctx->rb = chunkqueue_init();
    }

    return HANDLER_GO_ON;
}

A possible patch that worked for me is to look if the chunk queue already exists:

--- a/src/mod_fastcgi.c    2018-06-22 07:31:34.273162458 +0200
+++ b/src/mod_fastcgi.c    2018-06-22 08:10:17.881130326 +0200
@@ -508,7 +508,10 @@ static handler_t fcgi_check_extension(se
         hctx->opts.pdata = hctx;
         hctx->stdin_append = fcgi_stdin_append;
         hctx->create_env = fcgi_create_env;
-        hctx->rb = chunkqueue_init();
+        if(!hctx->rb)
+        {
+            hctx->rb = chunkqueue_init();
+        }
     }

     return HANDLER_GO_ON;

History

#1

Updated by gstrauss 21 days ago

  • Status changed from New to Patch Pending
  • Target version set to 1.4.50

Thanks for the report. While the FastCGI auth request likely fits in kernel socket send buffer to backend, it would be a good idea to reset hctx->rb if it was used for auth.

--- a/src/mod_fastcgi.c
+++ b/src/mod_fastcgi.c
@@ -515,7 +515,12 @@ static handler_t fcgi_check_extension(server *srv, connection *con, void *p_d, i
                hctx->opts.pdata = hctx;
                hctx->stdin_append = fcgi_stdin_append;
                hctx->create_env = fcgi_create_env;
-               hctx->rb = chunkqueue_init();
+               if (!hctx->rb) {
+                       hctx->rb = chunkqueue_init();
+               }
+               else {
+                       chunkqueue_reset(hctx->rb);
+               }
        }

        return HANDLER_GO_ON;

Also available in: Atom