使用ngx.eof 之后的部分会完整占用worker造成阻塞,不会进行协程切换

59 views
Skip to first unread message

chopin w.

unread,
Mar 5, 2024, 3:18:41 AMMar 5
to openresty
使用一个worker_processes 1 很容易复现。不知道官方知不知道这个问题。需要的话我可以贴一个复现case

chopin w.

unread,
Mar 5, 2024, 3:29:15 AMMar 5
to openresty
#user  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    server {
        listen       80;
        server_name  localhost;
        location = /notexisthost
        {
            proxy_pass http://xxxxx;  ##我这里设置了一个5秒才会响应的请求
            proxy_http_version 1.1;
            proxy_connect_timeout 10;
            proxy_send_timeout 10;
            proxy_read_timeout 10;
        }

        location = /test {
            content_by_lua_block {
                ngx.say("Before ngx.eof")
                ngx.log(ngx.INFO, "Before ngx.eof")
                ngx.eof()
                local ret  = ngx.location.capture('/notexisthost')
                ngx.log(ngx.ERR, "ngx eof running : status ", ret.status)
            }
        }
    }

}

连续请求localhost/test
第一次500ms 响应
第二次 将近5s才返回"Before ngx.eof",我的猜测是第一次请求的eof执行的时候占用了整个worker,并且没有按openresty的期望遇到网络io时进行协程切换,而导致第二次请求需要等第一次请求完整退出才能获得woker来执行请求
在2024年3月5日星期二 UTC+8 16:18:41<chopin w.> 写道:
使用一个worker_processes 1 很容易复现。不知道官方知不知道这个问题。需要的话我可以贴一个复现case

Junlong li

unread,
Mar 14, 2024, 9:00:44 PMMar 14
to openresty

你用的是哪个版本的 OpenResty ?

417132187

unread,
Mar 14, 2024, 9:01:05 PMMar 14
to Junlong li

chopin w.

unread,
Apr 25, 2024, 5:01:54 AMApr 25
to openresty
nginx version: openresty/1.15.8.3

在2024年3月15日星期五 UTC+8 09:01:05<4171...@qq.com> 写道:
Reply all
Reply to author
Forward
0 new messages