Skip to content

Lua script freeze nginx worker #2441

@dolgovas

Description

@dolgovas

Hello! I have a trouble with reload nginx-ingress.
I have a theory that k8s has so many ingress-crd inside, that lua blocking nginx worker and clients see 502 error.
I tried to re-create this scenario and it really possible to make this on test stand

pid /tmp/nginx/nginx.pid;
daemon off;
worker_processes 2;
worker_shutdown_timeout 240s ;
events {
	multi_accept        on;
	worker_connections  16384;
	use                 epoll;
}
http {
    lua_shared_dict dummy 1m;
    server {
        listen 8080;
        location / {
            return 200 "OK\n";
        }
    }
    init_worker_by_lua_block {
        ngx.log(ngx.ERR, "Heavy math start")
        local acc = 0
        for i = 1, 1e8 do
            acc = acc + math.sqrt(i) * math.sin(i) / (i + 1)
        end
        ngx.log(ngx.ERR, "Heavy math done")
    }
}
docker run --rm -it -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro -p 80:8080 registry.k8s.io/ingress-nginx/controller:v1.13.0 nginx

And you will see that depends on power of your machine nginx becomes ready after 10-20seconds.

Same situations happens when you will make nginx -s reload, master proccess started to route traffic to new workers BEFORE they becomes ready for it.

May be there is any possible solution to force nginx master process wait for complete initialization init_worker_by_lua_block { } and only after that started to route traffic on the new workers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions