pgmoon icon indicating copy to clipboard operation
pgmoon copied to clipboard

Support for HAProxy Lua non-blocking core.Socket

Open mecampbellsoup opened this issue 3 years ago • 3 comments

Description

We are using pgmoon inside of HAProxy Lua to connect to our Postgres DB server, make queries, establish LISTEN pgnotify clients, etc.

However the standard Lua Socket class is blocking as you can see from the source code.

TODO: describe the blocking nature of luasocket more clearly above

From an HAProxy blog post:

The Socket class is a replacement for the standard Lua Socket class and is compatible with HAProxy’s non-blocking nature. When you want to use socket functions in your actions, you must use this class.

As such we forked pgmoon and simply replaced luasocket with HAProxy's non-blocking Lua Socket class.

We'd like to discuss how to get his merged upstream so that others can benefit and we can get back onto using a non-forked pgmoon implementation.

I'll open a PR and link it to this issue with our naive implementation but we'd like to hear thoughts/suggestions on getting this feature merged.

Merry X-mas @leafo! 😄

cc @kriscode1

mecampbellsoup avatar Dec 25 '21 15:12 mecampbellsoup

The socket initialization is a bit confusing at the moment, but I think the best approach would be to provide a new sock_type option to the constructor that instructs the HAProxy module to be used.

leafo avatar Dec 25 '21 21:12 leafo

The socket initialization is a bit confusing at the moment, but I think the best approach would be to provide a new sock_type option to the constructor that instructs the HAProxy module to be used.

You mean this constructor (of the TCP socket) right?

mecampbellsoup avatar Dec 26 '21 18:12 mecampbellsoup

You mean this constructor (of the TCP socket) right?

There's already a socket_type argument passed to the constructor AFAICT.

https://github.com/mecampbellsoup/pgmoon/blob/da82db087b53450788204321d59afa44e3539a7a/pgmoon/socket.lua#L86-L93

mecampbellsoup avatar Dec 26 '21 18:12 mecampbellsoup