2

I have openresty app in docker container:

FROM openresty/openresty:xenial

RUN luarocks install luasocket

# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
ENV LUA_PATH="/usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/site/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua"
ENV LUA_CPATH="/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so"
CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]

Here is nginx.conf example:

server {
    listen       80;
    server_name  localhost;

    # disable code cache, do not need reload nginx with all changes
    lua_code_cache off;

    location / {
        rewrite_by_lua_block {
            local Core = require "core"
            Core.rewrite()
        }
    }
}

Core lua file source (with breakpoints on each line):

_G.debug = require("debug")

local Core = {}

function Core:rewrite()
    require("mobdebug").start("host.docker.internal")
    local a = 2
    ngx.say(a)
end

return Core

So, I try to use EmmyLua (IDEA) + mobdebug to debug my openresty app remotly.

IDEA directories config

After debug started + http call made:

Start mobdebug server at port:8172
Waiting for process connection...
Connected.

And nothing happens after that. I can see response from openresty, but debug is still active with message "Connected.".

What am I doing wrong?

  • the `init_by_lua_*` family of directives initializes the `nginx` instance; which is a different thread than the worker processes that ultimately handle the requests. If I remember correctly, you need to require things in one of the `init_worker_by_lua_*` directives instead, or they won't be found. – DarkWiiPlayer Jul 10 '19 at 06:07
  • Never mind that, I just checked and it doesn't matter. However, I found that disabling the Lua code cache causes variables declared in `init_by_lua` to be "forgotten". In conclusion, I guess my advise is: **Always require things locally where you need them**. In production, they may get cached, in dev they may get required each time; either way, that's an implementation detail. – DarkWiiPlayer Jul 10 '19 at 06:14
  • @DarkWiiPlayer, local requirements does not help. I have updated my question with the example. – Dmitriy Vorobey Jul 10 '19 at 19:35

2 Answers2

0

And has_breakpoint_file always logs time.lua... If I put few breakpoints - then all of them will be logged in set_breakpoint, but no one in has_breakpoint functions.

I don't see any issue with your setup. As long as the execution goes through that particular line and the debug hook is triggered, you should see a call to has_breakpoint (unless you are "stepping" through the code manually).

If this doesn't happen, then you may want to check if the code where you set breakpoints is executed in a coroutine, as the coroutine debugging should be explicitly enabled. See this documentation section for details.

If this still doesn't help, you may want to add some print commands to debug_hook function in mobdebug to see whether it's triggered on those lines with breakpoints and what happens after that.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
0

How do you run the docker image with exposed ports? Did you receive "Bind for 0.0.0.0:8172 failed: port is already allocated"?

Thank you, Irina

Irina
  • 939
  • 1
  • 8
  • 26