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

[bug] lua_socket_log_errors not working for ngx.socket.tcp():connect()

Open StarlightIbuki opened this issue 3 years ago • 1 comments

Version: openresty/1.21.4.

To reproduce:

# other stuff
http {
    include       mime.types;
    # ... other stuff
    lua_socket_log_errors off;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
            access_by_lua_block {
                local c = ngx.socket.tcp()
                c:connect("unix:/inexist.sock")
            }
        }
    }
}
curl localhost

We see

2022/12/27 18:14:28 [crit] 25707#0: *1 connect() to unix:/inexist.sock failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"

We expect lua_socket_log_errors to mute connect error.

StarlightIbuki avatar Dec 27 '22 10:12 StarlightIbuki

This error came from nginx event module https://github.com/nginx/nginx/blob/9c7a2c7ce4ad02a36df1bb0ee5e40a84610fffb9/src/event/ngx_event_connect.c#L242, openresty use ngx_event_connect_peer to connect ip:port, So it seems unable to avoid. Maybe openresty must describe this limitation in doc https://github.com/openresty/lua-nginx-module/blob/3f4005fa879fc2ed329275c47e238bff1f8b890e/src/ngx_http_lua_socket_tcp.c#L1442

oowl avatar Dec 27 '22 10:12 oowl