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

Require file with coroutine startup causes error

Open semyon422 opened this issue 9 months ago • 1 comments

test.lua:

coroutine.wrap(function() print("hello") end)()

Requiring with luajit:

$ luajit -e "require'test'"
hello

Requiring in content_by_lua_block:

http {
    server {
        listen 8080;
        lua_code_cache off;

        location / {
            content_by_lua_block {
                require("test")
            }
        }
    }
}
$ curl localhost:8080
500 error html page

Error log:

2025/04/06 18:49:55 [error] 2931732#0: *2 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
	[C]: in function 'require'
	content_by_lua(nginx.conf:15):2: in main chunk, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"

semyon422 avatar Apr 06 '25 13:04 semyon422

This issue seems similar to the issue https://github.com/openresty/lua-nginx-module/issues/376, it's a known limitation in LuaJIT.

You can also refer to lua-coroutine-yieldingresuming.

gavin0616 avatar Aug 12 '25 08:08 gavin0616