From 119a5f10e47f3507e58116002583e1226473485d Mon Sep 17 00:00:00 2001 From: Tim Duesterhus Date: Sat, 6 Jan 2018 19:16:25 +0100 Subject: [PATCH] BUG/MINOR: lua: Fix return value of Socket.settimeout 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.lua: http = require("socket.http") core.register_action("bug", { "http-req" }, function(txn) local b, c, h = http.request { url = "http://93.184.216.34", headers = { Host = "example.com" }, create = core.tcp, redirect = false } txn:set_var("txn.foo", c) end) haproxy.cfg: global lua-load /scratch/haproxy/http.lua frontend fe bind 127.0.0.1:8080 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)