Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement haproxy socket type from configuration #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mecampbellsoup
Copy link
Contributor

@mecampbellsoup mecampbellsoup commented Jun 7, 2022

Resolves #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

@@ -93,6 +99,8 @@ create_luasocket = do
ngx.socket.tcp!
when "luasocket"
create_luasocket!
when "haproxy"
create_luasocket("haproxy")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leafo using your create_luasocket interface now instead, just using the raw core.tcp wasn't playing well with the expected socket API.

@cesarmesones
Copy link

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

@pyreta
Copy link

pyreta commented Jun 8, 2022

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

plus one!

@JsmithCoreWeave
Copy link

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

Would be helpful for us as well.

@leafo
Copy link
Owner

leafo commented Jun 14, 2022

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)

@mecampbellsoup
Copy link
Contributor Author

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.

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for HAProxy Lua non-blocking core.Socket
5 participants