HAProxy LUA not able to load LUA module cjson

Hello,

The LUA with HAproxy is not able to load cjson and LUA execution exits.

> Is there special cjson.so inclusion required in HAProxy config or LUA file?

 local function foo()
        core.log(core.info, "In foo")

        local json = require('cjson')

        core.log(core.info, "Out foo")
end

function choose_backend(txn)

       foo()

        return "app"
end

core.register_fetches("choose_backend", choose_backend)

Only prints below log in HAProxy logs
In foo


frontend http-in
    mode http

    bind *:443 ssl crt /etc/haproxy/server.pem ca-file /etc/haproxy/ca.crt verify required

    **use_backend %[lua.choose_backend]**
   
    reqadd X-Forwarded-Proto:\ https if { ssl_fc }
    option forwardfor

The same cjson on same centos machine works with standalone lua problem.

$ cat helloworld
-- hello world lua program
print ("Hello World!")


local function foo()
        print ("In foo")

        local json = require('cjson')

        print ("Out foo")
end

foo()

Prints - lua helloworld
Hello World!
In foo
Out foo

The cjson is installed on centos machine

$ rpm -ql lua-cjson
/usr/bin/json2lua
/usr/bin/lua2json
/usr/lib64/lua/5.1/cjson.so
/usr/share/doc/lua-cjson-2.1.0
/usr/share/doc/lua-cjson-2.1.0/LICENSE
/usr/share/doc/lua-cjson-2.1.0/NEWS
/usr/share/doc/lua-cjson-2.1.0/THANKS
/usr/share/doc/lua-cjson-2.1.0/manual.html
/usr/share/doc/lua-cjson-2.1.0/manual.txt
/usr/share/doc/lua-cjson-2.1.0/performance.html
/usr/share/doc/lua-cjson-2.1.0/performance.txt
/usr/share/doc/lua-cjson-2.1.0/rfc4627.txt
/usr/share/lua/5.1/cjson
/usr/share/lua/5.1/cjson/tests
/usr/share/lua/5.1/cjson/tests/README
/usr/share/lua/5.1/cjson/tests/bench.lua
/usr/share/lua/5.1/cjson/tests/example1.json
/usr/share/lua/5.1/cjson/tests/example2.json
/usr/share/lua/5.1/cjson/tests/example3.json
/usr/share/lua/5.1/cjson/tests/example4.json
/usr/share/lua/5.1/cjson/tests/example5.json
/usr/share/lua/5.1/cjson/tests/genutf8.pl
/usr/share/lua/5.1/cjson/tests/numbers.json
/usr/share/lua/5.1/cjson/tests/octets-escaped.dat
/usr/share/lua/5.1/cjson/tests/rfc-example1.json
/usr/share/lua/5.1/cjson/tests/rfc-example2.json
/usr/share/lua/5.1/cjson/tests/test.lua
/usr/share/lua/5.1/cjson/tests/types.json
/usr/share/lua/5.1/cjson/util.lua

Hi,

HAProxy sends error log if Lua ends with an error.
These errors are sent on the same way than the proxy logs.

In other way, haproxy requires lua-5.3, your cjson file are compiled with the lua5-1 version.

Thierry