pgmoon icon indicating copy to clipboard operation
pgmoon copied to clipboard

implement haproxy socket type from configuration

Open mecampbellsoup opened this issue 2 years ago • 6 comments

Resolves https://github.com/leafo/pgmoon/issues/114.

When the Lua HAProxy core object is detected, the socket class will automatically use its (non-blocking) socket type. The pattern is similar to existing auto-detection of whether pgmoon is running inside an NGINX context or not and choosing that socket type if so.

http://www.arpalert.org/src/haproxy-lua-api/1.7/index.html#core.get_info

mecampbellsoup avatar Jun 07 '22 21:06 mecampbellsoup

we are also using haproxy in lua and would love to be able to use this api!

cesarmesones avatar Jun 08 '22 22:06 cesarmesones

we are also using haproxy in lua and would love to be able to use this api!

plus one!

pyreta avatar Jun 08 '22 22:06 pyreta

we are also using haproxy in lua and would love to be able to use this api!

Would be helpful for us as well.

JsmithCoreWeave avatar Jun 13 '22 13:06 JsmithCoreWeave

Just adding comment in case it's helpful to anyone: if it's API compatible with LuaSocket then you can run package.loaded.socket = core before creating your connection object.

Be warned, I have no idea how this will play with ssl. (This change in this patch too is unknown)

leafo avatar Jun 14 '22 18:06 leafo

Just adding comment in case it's helpful to anyone: if it's API compatible with LuaSocket then you can run package.loaded.socket = core before creating your connection object.

I tried using pgmoon:master without our HAProxy-specific changes and putting package.loaded.socket = core in our connect DB function as follows:

function connect_db(pg_settings)
    -- Returns a pgmoon postgres object or nil on failure.

    package.loaded.socket = core

    local pg = pgmoon.new(pg_settings)
    -- Set the timeout value (in milliseconds) for all socket operations
    -- (connect, write, receive)
    pg:settimeout(5000)
    pg.convert_null = true -- https://github.com/leafo/pgmoon#converting-nulls
    local success, err = pg:connect()

However this does not seem to work.

mecampbellsoup avatar Jul 06 '23 20:07 mecampbellsoup

if it's API compatible with LuaSocket then you can run package.loaded.socket = core before creating your connection object.

Surprising it didn't work since the HAProxy Lua API docs specify the same constraint:

This class must be compatible with the Lua Socket class. Only the ‘client’ functions are available.

https://www.arpalert.org/src/haproxy-lua-api/2.6/index.html#Socket

mecampbellsoup avatar Jul 06 '23 21:07 mecampbellsoup