Hi,

Now, because of you I have my own freebsd installed :). I can
reproduced the segfault. I suppose that the OS other than Freebsd are
impacted, but luckyly it not visible.

I encounter an easy compilation error. So can you test the two attached
patches. The first one fix the compilation issue, and the second one
fix he segfault.

Thierry


On Mon, 2 Nov 2015 20:50:01 +0100
PiBa-NL <piba.nl....@gmail.com> wrote:

> Op 2-11-2015 om 10:03 schreef Thierry FOURNIER:
> > On Sat, 31 Oct 2015 21:22:14 +0100
> > PiBa-NL <piba.nl....@gmail.com> wrote:
> >
> >> Hi Thierry, haproxy-list,
> >
> > Hi Pieter,
> Hi Thierry,
> >
> >
> >> I've created another possibly interesting lua script, and it works :)
> >> (mostly). (on my test machine..)
> >>
> >> When i visit the 192.168.0.120:9003 website i always see the 'Hello
> >> World' page. So in that regard this is usable, it is left to the browser
> >> to send the request again, not sure how safe this is in regard to
> >> mutations being send twice. It should probably check for POST requests
> >> and then just return the error without replacing it with a redirect..
> >> Not sure if that would catch all problem cases..
> >>
> >> Ive created a lua service that counts how many requests are made, and
> >> returns a error status every 5th request.
> >> Second there is a lua response script that checks the status, and
> >> replaces it by a redirect if it sees the faulty status 500.
> >> This does currently result in the connection being closed and reopened
> >> probably due to the txn.res:send().?.
> >>
> >> Though i am still struggling with what is and isn't supposed to be 
> >> possible.
> >> For example the scripts below are running in 'mode http' and mostly just
> >> changing 'headers'.
> >> I expected to be able to simply read the status by calling
> >> txn.f:status() but this always seems to result in 'null'.
> >> Manually parsing the response buffer duplicate works but seems ugly..
> >>
> >> txn.f:status()  <  it doesnt result in the actual status.
> >
> > This is a bug wich I reproduce. Can you try the attached patches ?
> With the patches it works without my 'workaround', thanks.
> >
> >> txn.res:set()  < if used in place of send() causes 30 second delay
> >
> > This function put data in the input part of the response buffer. This
> > new data follows the HAProxy stream when the Lua script is finished.
> > It is your case.
> >
> > I can't reproduce this behaviour, I suppose that its because I work
> > locally, and I'm not impacted by the network latency.
> Even when i bind everything to 0.0.0.0 and use 127.0.0.1 to query the 
> 9003 port it still waits for the timeout to strike..
> I'm not sure why it doesn't happen in your setup.. Of course i'm running 
> on FreeBSD, but i don't expect that to affect this..
> >
> >
> >> txn.done()  < dumps core. (im not sure when ever to call it? the script
> >> below seems to match the description that this function has.?.)
> >
> > I can't reproduce too, for the same reasons, I guess.
> Please note that both set() and done() need to be uncommented for the 
> dump to happen, with the 5th request.
> 
> Not sure if it helps, but backtrace of the dump below (would 'bt full' 
> be more usefull?):
> (gdb) bt
> #0  0x0000000801a76bb5 in memmove () from /lib/libc.so.7
> #1  0x0000000000417523 in buffer_insert_line2 (b=0x8024a0000,
>      pos=0x8024a0035 "\r\n\ncontent-type: text/plain\r\ncontent-length: 
> 394\r\n\r\nError 5\r\nversion\t\n[HTTP/1.1]\t\nf\t\n   0\t\n   
> [userdata: 0x802683a68]\t\nsc\t\n   0\t\n   [userdata: 
> 0x802683be8]\t\nc\t\n 0\t\n   [userdata: 0x802683b68]\t\nheader"...,
>      str=0x58c695 "Connection: keep-alive", len=22) at src/buffer.c:126
> #2  0x000000000047b3a5 in http_header_add_tail2 (msg=0x8024bb290, 
> hdr_idx=0x8024bb280, text=0x58c695 "Connection: keep-alive", len=22)
>      at src/proto_http.c:595
> #3  0x000000000047f943 in http_change_connection_header 
> (txn=0x8024bb280, msg=0x8024bb290, wanted=8388608) at src/proto_http.c:2079
> #4  0x00000000004900fd in http_process_res_common (s=0x802485600, 
> rep=0x802485650, an_bit=262144, px=0x8024de000) at src/proto_http.c:6882
> #5  0x00000000004d6c90 in process_stream (t=0x8024ab710) at 
> src/stream.c:1918
> #6  0x0000000000420588 in process_runnable_tasks () at src/task.c:238
> #7  0x000000000040ce0e in run_poll_loop () at src/haproxy.c:1559
> #8  0x000000000040dcb2 in main (argc=4, argv=0x7fffffffeb00) at 
> src/haproxy.c:1912
> 
> >
> >> Am i trying to do it wrong?
> >>
> >> p.s. Is 'health checking' using lua possible? The redis example looks
> >> like a health 'ping'.. It could possibly be much much more flexible then
> >> the tcp-check send  / tcp-check expect routines..
> >
> > It is not possible. You can write a task which do something (like an
> > http request) and reuse the result in the request processing Lua code,
> > but this task cannot set the status of the server.
> The doc does say for core.register_task(func) "For example this type of 
> tasks can be executed to perform complex health checks." but if i 
> understand correctly it is so that we can perform healthchecks with it, 
> but the results of such a check cannot be used to change a servers 
> health.? Probably the text near this register_task could use some 
> tweaking then?.
> 
> > Thierry
> >
> >
> >> I'm currently testing with HA-Proxy version 1.7-dev0-e4c4b7d and the
> >> following configuration files:
> >>
> >> #### haproxy.cfg ###
> >> global
> >>       maxconn            6000
> >>       lua-load        /var/etc/haproxy/luascript_lua-count5error
> >> defaults
> >>       timeout connect        30000
> >>       timeout server        30000
> >>       timeout client        30000
> >>       mode            http
> >>       log            global
> >> frontend TEST-lua-count
> >>       bind            192.168.0.120:9002
> >>       option            http-keep-alive
> >>       http-request use-service lua.lua-count
> >>
> >> frontend TEST-lua-retry-serverror
> >>       bind            192.168.0.120:9003
> >>       option            http-keep-alive
> >>       http-request lua.retrystorerequest
> >>       http-response lua.retryerrors
> >>       default_backend hap_9002_http_ipvANY
> >>
> >> backend hap_9002_http_ipvANY
> >>       mode            http
> >>       retries            3
> >>       server            192.168.0.120_9002 192.168.0.120:9002
> >>
> >> ### luascript_lua-count5error ###
> >> core.register_action("retryerrors" , { "http-res" }, function(txn)
> >>       local clientip = txn.f:src()
> >>       txn:Info("  LUA client " .. clientip)
> >>
> >>       local s = txn.f:status() -- doesnt work?
> >>       if s == null then
> >>           core.Info("LUA txn.s:status RETURNED: NULL, fallback needed ??")
> >>           local req = txn.res:dup()
> >>           local statusstr = string.sub(req, 10, 13)
> >>           s = tonumber(statusstr)
> >>       end
> >>       core.Info("LUA status " .. s)
> >>
> >>       if s ~= 200 then
> >>           txn:Info("LUA REDIRECT IT ! " .. s)
> >>
> >>           local url = txn:get_priv()
> >>           local response = ""
> >>           response = response .. "HTTP/1.1 302 Moved\r\n"
> >>           response = response .. "Location: " .. url .."\r\n"
> >>           response = response .. "\r\n"
> >>
> >>           txn.res:send(response)
> >>           --txn.res:set(response) -- causes 30 second delay..
> >>           --txn:done() --dumps core..
> >>       end
> >> end);
> >>
> >> core.register_action("retrystorerequest" , { "http-req" }, function(txn)
> >>       local url = txn.f:url()
> >>       txn:set_priv(url);
> >> end);
> >>
> >> core.register_service("lua-count", "http", function(applet)
> >>      if test == null then
> >>         test = 0
> >>      end
> >>      test = test + 1
> >>      local response = ""
> >>      if test % 5 == 0 then
> >>         applet:set_status(500)
> >>         response = "Error " .. test
> >>      else
> >>         applet:set_status(200)
> >>         response = "Hello World !" .. test
> >>      end
> >>      applet:add_header("content-length", string.len(response))
> >>      applet:add_header("content-type", "text/plain")
> >>      applet:start_response()
> >>      applet:send(response)
> >> end)
> >>
> >>
> 
>From e65dfa93f62f8f9434d11a5309a8eb4f6cb8970e Mon Sep 17 00:00:00 2001
From: Thierry FOURNIER <tfourn...@arpalert.org>
Date: Tue, 3 Nov 2015 19:17:37 +0100
Subject: [PATCH 1/2] BUILD: freebsd: double declaration

On freebsd, the macro LIST_PREV already exists in the header file
<sys/queue.h>, and this makes a build error.

This patch removes the macros before declaring it. This ensure
that the error doesn't occurs.
---
 include/common/mini-clist.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/common/mini-clist.h b/include/common/mini-clist.h
index cb905da..da24b33 100644
--- a/include/common/mini-clist.h
+++ b/include/common/mini-clist.h
@@ -111,6 +111,7 @@ struct cond_wordlist {
  * which contains list head <lh>, which is known as element <el> in
  * struct pt.
  */
+#undef LIST_PREV
 #define LIST_PREV(lh, pt, el) (LIST_ELEM((lh)->p, pt, el))
 
 /*
-- 
2.1.4

>From 50c125d384b2974a8cfe8c2e6321eedbcb60cfab Mon Sep 17 00:00:00 2001
From: Thierry FOURNIER <tfourn...@arpalert.org>
Date: Wed, 4 Nov 2015 10:52:59 +0100
Subject: [PATCH 2/2] BUG/MEDIUM: lua: clean output buffer

When the txn.done() fiunction is called, the ouput buffer is cleaned,
but the associated relative pointer on the HTTP requests elements
is not reseted.

This patch remove this cleanup, because the output buffer may contain
data to forward.
---
 src/hlua.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/hlua.c b/src/hlua.c
index 652365c..6b929b5 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -4818,10 +4818,6 @@ __LJMP static int hlua_txn_done(lua_State *L)
 		htxn->s->txn->req.msg_state = HTTP_MSG_CLOSED;
 		htxn->s->txn->rsp.msg_state = HTTP_MSG_DONE;
 
-		/* Trim any possible response */
-		oc->buf->i = 0;
-		htxn->s->txn->rsp.next = htxn->s->txn->rsp.sov = 0;
-
 		/* Note that if we want to support keep-alive, we need
 		 * to bypass the close/shutr_now calls below, but that
 		 * may only be done if the HTTP request was already
-- 
2.1.4

Reply via email to