lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

Connection leak in ngx.location.capture()

Open sorc1 opened this issue 4 years ago • 4 comments

The following settings lead to connections leak in nginx():

server {
  listen 8081;
  server_name  localhost;
  proxy_buffering on;
  proxy_buffers 8 128k;
  proxy_max_temp_file_size 0;
  location /a/ {
    content_by_lua_block {
      local data = ngx.location.capture('/b/')
      ngx.say("ok")
    }
  }
  location /b/ {
    proxy_pass http://127.0.0.1:8082/get/;
  }
  location /s/ {
    stub_status;
  }
}

If http://127.0.0.1:8082/get/ returned more than 1m (8 * 128k) of data then the upstream connection hangs. It still hangs even if the client connection breaks. You can easily see the leakage by configuring nginx with --with-http_stub_status_module option and by requesting http://127.0.0.1:8081/s/. Normal case (before requests):

Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0 

After 3 requests:

Active connections: 4 
server accepts handled requests
 5 5 5 
Reading: 0 Writing: 4 Waiting: 0 

You can setup a server for http://127.0.0.1:8082/get/ with the following configuration:

server {
  listen 8082;
  server_name  localhost;

  location /get/ {
    content_by_lua_block {
      ngx.say(string.rep(" ", 8*1024*1024))
    }
  }
}

Note that all works fine when proxy_buffering off; is set.

sorc1 avatar Feb 24 '21 06:02 sorc1

@agentzh I have replicated this issue with an older 1.21 nginx and lua nginx module. On my TODO list is to confirm against a more up-to date nginx in the coming months.

There is definately a leak in connection stats, however I don't think there is any actual connection objects leaked.

Any ideas?

splitice avatar Apr 11 '23 13:04 splitice

This needs to be debugged

zhuizhuhaomeng avatar Apr 11 '23 14:04 zhuizhuhaomeng

This needs to be debugged

this issue

This needs to be debugged

Can I modify this task

JMFOREVER avatar Jun 19 '23 11:06 JMFOREVER

Yes, yes

On Mon, Jun 19, 2023, 6:02 AM JMFOREVER @.***> wrote:

This needs to be debugged

this issue

This needs to be debugged

Can I modify this task

— Reply to this email directly, view it on GitHub https://github.com/openresty/lua-nginx-module/issues/1857#issuecomment-1596976378, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6QCT4PN7K4P2PA47CZLP2DXMAWV5ANCNFSM4YD453MA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Scott41382 avatar Jun 20 '23 02:06 Scott41382