rewrite_by_lua_block {;} in nginx_kong.lua file causes run-time issues
Is there an existing issue for this?
- [x] I have searched the existing issues
Kong version ($ kong version)
3.9.1
Current Behavior
With kong 3.9.1, when we hit our service api, kong crashes and throws 500 internal server error with following logs:
2025/11/25 13:30:22 [error] 10601#0: 1289 failed to run balancer_by_lua: .../luarocks/share/lua/5.1/kong/init.lua:1432: attempt to call upvalue 'enable_keepalive' (a nil value) stack traceback: .../luarocks/share/lua/5.1/kong/init.lua:1432: in function 'balancer' balancer_by_lua(nginx-kong.conf:72):2: in main chunk while connecting to upstream, client: 172.17.0.32, server: kong, request: "GET /v1/api HTTP/1.1", host: "url:port", request_id: "******************************" 2025/11/25 13:30:22 [error] 10601#0: *1289 failed to load inlined Lua code: rewrite_by_lua(nginx-kong.conf:330):1: unexpected symbol near ';', client: 172.17.0.32
nginx-kong.conf has following text at line 330 (which looks to be a syntax error from lua point of view): rewrite_by_lua_block {;}
This error seems to be coming from the kong open source code in file "nginx_kong.lua" line "rewrite_by_lua_block {;}".
We request inputs for this.
Thanks.
Expected Behavior
Expected response is 200 Ok for the service api hit through kong api gateway
Steps To Reproduce
As mentioned in description, we are running kong 3.9.1. Hit our service api through kong (using curl on command line) kong crashes and throws 500 internal server error response. Error logs show the syntax error for rewrite_by_lua_block {;} most likely from file nginx_kong.lua.
Note: We are not adding any additional nginx lua code from any of our modules.
Anything else?
No response
hello @p-thamke ,
rewrite_by_lua_block {;}
Is a valid syntax for the nginx config file. That same syntax is used extensively in other places:
access_by_lua_block {;}
header_filter_by_lua_block {;}
body_filter_by_lua_block {;}
log_by_lua_block {;}
I think the relevant error is not on that log line, but on the previous one:
failed to run balancer_by_lua: .../luarocks/share/lua/5.1/kong/init.lua:1432: attempt to call upvalue 'enable_keepalive' (a nil value)
That indicates that the Lua function enable_keepalive was not properly loaded (is a nil value), which should never happen. If this is happening there's probably something wrong with your configuration - I would start by looking at your prefix config option. It does look like Kong does not know where its own files are.
Hi @kikito, Thanks for the response.
We are using OpenResty for kong 3.9.1 and seems it expects a valid "Lua" code. A lone semicolon is not a valid Lua code due to which it throws syntax error. We tested internally (no code check-ins) by editing nginx_kong.lua to replace rewrite_by_lua_block {;} as follows: rewrite_by_lua_block { return } This resolved the syntax error.
For enable_keepalive, seems it expects some other dependency (like lua-resty-core or lua-resty-lrucache).
As next steps, we'll do this - we'll resolve the dependency for "enable_keepalive" and will re-test this with original code rewrite_by_lua_block {;} .
Hi @p-thamke, Thanks for your feedback.
Could you provide a minimal configuration to reproduce this issue?
Hi @Water-Melon , I'll be sharing the configuration asap here. Thanks.
Hi @Water-Melon , We are building kong 3.9.1 (for DB-less mode) from source (with openresty 1.25.3.2)
kong.conf contents: proxy_access_log = ${LocalPath}/api_access.log proxy_error_log = ${LocalPath}/api_error.log admin_access_log = ${LocalPath}/admin_access.log admin_error_log = ${LocalPath}/admin_error.log status_error_log = ${LocalPath}/status_error.log proxy_listen = 0.0.0.0:50051 reuseport backlog=16384, 0.0.0.0:50053 http2 ssl reuseport backlog=16384 admin_listen = 127.0.0.1:50052 reuseport backlog=16384 nginx_user = root nginx_worker_processes = 2 mem_cache_size = 12m database = off plugins = bundled
We start kong as: ${InstallPath}/bin/kong start -c kong.conf -p kong_node
We get following syntax error: failed to load inlined Lua code: rewrite_by_lua(nginx-kong.conf:330):1: unexpected symbol near ';', client: 172.17.0.32
JFI, our nginx-kong.conf has following text at line 330 (which looks to be a syntax error from lua point of view): rewrite_by_lua_block {;}
This error is coming from the kong open source code in file "../luarocks/share/lua/5.1/kong/templates/nginx_kong.lua" line "rewrite_by_lua_block {;}".
We tested internally by updating this line as follows and the syntax error was gone: rewrite_by_lua_block { return }
Please let know if nginx configuration details (from nginx-kong.conf) are required. In that case, I'll need to curtail product specific data and share it.
Thanks.
This issue is marked as stale because it has been open for 14 days with no activity.