Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx.location.capture subrequest freeze in combination with NJS #2390

Open
dominikmahler opened this issue Jan 27, 2025 · 0 comments
Open

ngx.location.capture subrequest freeze in combination with NJS #2390

dominikmahler opened this issue Jan 27, 2025 · 0 comments

Comments

@dominikmahler
Copy link

dominikmahler commented Jan 27, 2025

Hi,

I have following situation.

I have a nginx plus ingress controller running inside Kubernetes. Nginx exposes a service with a location:

server {
      listen 80;
      listen [::]:80;

      server_name luatest.com;
      error_log stderr debug;

      location /init {
        rewrite_by_lua_file /etc/nginx/lua/rewrite.lua;
      }
      include /etc/nginx/custom-conf/*.conf;
    }

The rewrite.lua script looks like this:

    ngx.log(ngx.INFO, "start lua process")
    local res_cookie = ngx.location.capture("/testlocation")
    ngx.say("I am ok") ngx.exit(200)
    ngx.log(ngx.INFO, "did subrequest")

The script sends a subrequest to following location:

    location /testlocation {
        internal;
        js_content request_handling.request_handling;
    } 

Further, the njs script does following:

    async function request_handling(r) {
      r.log("here in njs script");
      let test= await r.subrequest('/njs_target');
      r.log("did subrequest from njs to location");
      r.return(200, test);
      return;
    }
    export default {request_handling}

As soons as i do a curl request to the location /init the request stucks until i terminate the connection, or some timeout kicks in.
Inside the Nginx debug logs, i can see the last log lines from njs and the nginx line "http finalize request: 0, "/njs_target?" a:0, c:3" which should close everything and return back to LUA, but its not the case.
These are the last debug logs:

[info] 25#25: *3 js: here in njs script
[debug] 25#25: *3 posix_memalign: 00006166EFF0A4A0:4096 @16
[debug] 25#25: *3 http subrequest "/njs_target?"
[debug] 25#25: *3 http finalize request: -4, "/testlocation?" a:0, c:4
[debug] 25#25: *3 http request count:4 blk:0
[debug] 25#25: *3 http posted request: "/njs_target?"
[debug] 25#25: *3 rewrite phase: 1
[debug] 25#25: *3 test location: "/njs_target"
[debug] 25#25: *3 using configuration "/njs_target"
[debug] 25#25: *3 http cl:-1 max:1048576
[debug] 25#25: *3 rewrite phase: 3
[debug] 25#25: *3 http output filter "/njs_target?"
[debug] 25#25: *3 http copy filter: "/njs_target?"
[debug] 25#25: *3 http postpone filter "/njs_target?" 00007FFCA7882B40
[debug] 25#25: *3 http postpone filter in memory
[debug] 25#25: *3 http postpone filter in memory 7 bytes
[debug] 25#25: *3 http copy filter: 0 "/njs_target?"
[debug] 25#25: *3 http finalize request: 0, "/njs_target?" a:0, c:3
[info] 25#25: *3 js: did subrequest from njs to location
[debug] 25#25: *3 http output filter "/testlocation?"
[debug] 25#25: *3 http copy filter: "/testlocation?"
[debug] 25#25: *3 http copy filter: 0 "/testlocation?"
[debug] 25#25: *3 http request count:3 blk:0
[debug] 25#25: *3 delete posted event 00006166F0044560
[debug] 25#25: *3 http run request: "/init?"
[debug] 25#25: *3 rewrite phase: 4

If i terminate the curl command on the client side, these two lines show up in the nginx logs:

[debug] 26#26: *4 http run request: "/init?"
[debug] 26#26: *4 http reading blocked

If i remove the njs subrequest, it is working again, but from my side it seems LUA is waiting for something if i enable the NJS subrequest, but i cant figure out what it is.

Version overview of the test environment:

NJS: 0.8.5
LUA: 0.10.26
Nginx: nginx/1.25.5 (nginx-plus-r32-p1)

I also had the same behavior with the latest NJS Version 0.8.8 and NGINX plus r33.

One more thing to mention, everything is working with following version:

NJS: 0.7.11
LUA: 10.22
Nginx: nginx/1.23.2 (nginx-plus-r28)

Many thanks in advance.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant