Welcome! Log In Create A New Profile


[PATCH] BUG/MINOR: lua: Fix return value of Socket.settimeout

Posted by Tim Duesterhus 
Tim Duesterhus
[PATCH] BUG/MINOR: lua: Fix return value of Socket.settimeout
January 06, 2018 07:20PM
The `socket.tcp.settimeout` method of Lua returns `1` in all cases,
while the `Socket.settimeout` method of haproxy returns `0` in all
cases. This breaks the `socket.http` module, because it validates
the return value of `settimeout`.

This bug was introduced in commit 7e7ac32dad1e15c19152d37aaf9ea6b3f00a7226
(which is the very first commit adding the Socket class to Lua). This
bugfix should be backported to every branch containing that commit:
- 1.6
- 1.7
- 1.8

A test case for this bug is as follows:

The 'Test' response header will contain an HTTP status code with the
patch applied and will be zero (nil) without the patch applied.

http = require("socket.http")

core.register_action("bug", { "http-req" }, function(txn)
local b, c, h = http.request {
url = "";,
headers = {
Host = "example.com"
create = core.tcp,
redirect = false

txn:set_var("txn.foo", c)

lua-load /scratch/haproxy/http.lua

frontend fe
http-request lua.bug
http-response set-header Test %[var(txn.foo)]

default_backend be

backend be
server s example.com:80
src/hlua.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/hlua.c b/src/hlua.c
index 3d5a81cac..fa629ba94 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2490,7 +2490,7 @@ __LJMP static int hlua_socket_settimeout(struct lua_State *L)
s->res.wto = tmout;
xref_unlock(&socket->xref, peer);

- return 0;
+ return 1;

__LJMP static int hlua_socket_new(lua_State *L)
Sorry, only registered users may post in this forum.

Click here to login