nginx 为什么我不能在init_by_lua阶段使用ngx.socket.tcp()?

guicsvcw  于 2023-05-28  发布在  Nginx
关注(0)|答案(1)|浏览(222)

我需要从unix socket(postgresql)中读取API定义并将其设置为共享dict中的变量。有什么理由禁止这样做吗?

local pg = pgmoon.new({
        socket_type = "nginx",
        host = table.concat({"unix:", config.socket}),
        database = config.database,
        user = config.user
    })

    assert(pg:connect())
    local res = assert(pg:query("select info from testy limit 1"))
    return res

与...相撞

nginx: [error] init_by_lua_file error: /usr/local/share/lua/5.1/pgmoon/socket.lua:99: no request found
stack traceback:
        [C]: in function 'tcp'
        /usr/local/share/lua/5.1/pgmoon/socket.lua:99: in function 'new'
        /usr/local/share/lua/5.1/pgmoon/init.lua:1093: in function '__init'
        /usr/local/share/lua/5.1/pgmoon/init.lua:1101: in function 'new'
        ./lua/store.lua:7: in function 'read'
        .../peter/Documents/resty-engine/src/lua/lifecycle/init.lua:8: in function 'reloadAPI'
        .../peter/Documents/resty-engine/src/lua/lifecycle/init.lua:16: in main chunk

同样的问题也会发生,如果你只是插入

local socket = ngx.socket.tcp()

init_by_lua_block或file

k2fxgqgv

k2fxgqgv1#

根据记录
cosocket当前在init_by_lua*init_worker_by_lua*指令上下文中被[...]禁用

相关问题