I forgot lua file content :

# cat mylua.lua 
-- a simple mirror web server
-- it generates a response whose body contains the requests headers
function mirror(txn)
        local buffer = ""
        local response = ""
        local mydate = txn.sc:http_date(txn.f:date())

        buffer = buffer .. "You sent the following headers\r\n"
        buffer = buffer .. "===============================================\r\n"
        buffer = buffer .. txn.req:dup()
        buffer = buffer .. "===============================================\r\n"

        response = response .. "HTTP/1.0 200 OK\r\n"
        response = response .. "Server: haproxy-lua/mirror\r\n"
        response = response .. "Content-Type: text/html\r\n"
        response = response .. "Date: " .. mydate .. "\r\n"
        response = response .. "Content-Length: " .. buffer:len() .. "\r\n"
        response = response .. "Connection: close\r\n"
        response = response .. "\r\n"
        response = response .. buffer

        txn.res:send(response)
        txn:close()
end

On Wed, 12 Aug 2015 18:57:50 +0200,
Marc-Antoine <[email protected]> wrote :

> Hi,
> 
> i try to test lua in haproxy and i got segfault while doing curl request :
> 
> # curl http://127.0.0.1 -H "X-debug-me: yes"
> curl: (52) Empty reply from server
> 
> ---
> 
> # gdb ./haproxy
> GNU gdb (GDB) 7.4.1-debian
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "x86_64-linux-gnu".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from /root/haproxy/haproxy...done.
> (gdb) run -f /etc/haproxy/haproxy.cfg -db
> Starting program: /root/haproxy/haproxy -f /etc/haproxy/haproxy.cfg -db
> 
> Program received signal SIGSEGV, Segmentation fault.
> __memmove_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:2976
> 2976    ../sysdeps/x86_64/multiarch/memcpy-ssse3.S: Aucun fichier ou dossier 
> de ce type.
> (gdb) bt 
> #0  __memmove_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:2976
> #1  0x00000000004130a9 in buffer_insert_line2 (b=0x7e53b0, pos=0x7e541c 
> "\r\n", str=0x782850 "", len=20) at src/buffer.c:126
> #2  0x0000000000468c99 in http_header_add_tail2 (msg=0x7cd5a0, 
> hdr_idx=0x7cd540, text=0x782850 "", len=20) at src/proto_http.c:507
> #3  0x0000000000472ebb in http_process_request (s=0x7cd1e0, req=0x7cd1f0, 
> an_bit=512) at src/proto_http.c:4596
> #4  0x00000000004b7202 in process_stream (t=0x7d4cb0) at src/stream.c:1741
> #5  0x00000000004196c4 in process_runnable_tasks () at src/task.c:238
> #6  0x000000000040c148 in run_poll_loop () at src/haproxy.c:1515
> #7  0x000000000040cca2 in main (argc=4, argv=0x7fffffffe6f8) at 
> src/haproxy.c:1874
> 
> ---
> 
> # ./haproxy -vv
> HA-Proxy version 1.6-dev3-03d0e4-59 2015/08/11
> Copyright 2000-2015 Willy Tarreau <[email protected]>
> 
> Build options :
>   TARGET  = linux2628
>   CPU     = generic
>   CC      = gcc
>   CFLAGS  = -O0
>   OPTIONS = USE_ZLIB=1 USE_OPENSSL=1 USE_PCRE=1
> 
> Default settings :
>   maxconn = 2000, bufsize = 16384, maxrewrite = 8192, maxpollevents = 200
> 
> Encrypted password support via crypt(3): yes
> Built with zlib version : 1.2.7
> Compression algorithms supported : identity("identity"), deflate("deflate"), 
> raw-deflate("deflate"), gzip("gzip")
> Built with OpenSSL version : OpenSSL 1.0.1e 11 Feb 2013
> Running on OpenSSL version : OpenSSL 1.0.1e 11 Feb 2013
> OpenSSL library supports TLS extensions : yes
> OpenSSL library supports SNI : yes
> OpenSSL library supports prefer-server-ciphers : yes
> Built with PCRE version : 8.30 2012-02-04
> PCRE library supports JIT : no (USE_PCRE_JIT not set)
> Built with Lua version : Lua 5.3.1
> Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT 
> IP_FREEBIND
> 
> Available polling systems :
>       epoll : pref=300,  test result OK
>        poll : pref=200,  test result OK
>      select : pref=150,  test result OK
> Total: 3 (3 usable), will use epoll.
> 
> ---
> 
> global
>         log /dev/log    local0
>         chroot /var/lib/haproxy
>         stats socket /run/haproxy/admin.sock mode 660 level admin
>         stats timeout 30s
>         user haproxy
>         group haproxy
>         daemon
>         nbproc 1
> 
>         # Default SSL material locations
>         ca-base /etc/ssl/certs
>         crt-base /etc/ssl/private
> 
>         # Default ciphers to use on SSL-enabled listening sockets.
>         # For more information, see ciphers(1SSL).
>         ssl-default-bind-ciphers 
> kEECDH+aECDSA+AES:kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
>         ssl-default-bind-options no-sslv3
> 
>         lua-load /root/haproxy/mylua.lua
> 
> defaults
>         log     global
>         mode    http
>         option  httplog
>         option log-health-checks
>         option log-separate-errors
> 
>         maxconn 19500        # Should be slightly smaller than global.maxconn.
>         timeout client 60s   # Client and server timeout must match the 
> longest
>         timeout server 60s   # time we may wait for a response from the 
> server.
>         timeout queue  60s   # Don't queue requests too long if saturated.
>         timeout connect 4s   # There's no reason to change this one.
>         timeout http-request 5s # A complete request may never take that long.
>         # Uncomment the following one to protect against nkiller2. But 
> warning!
>         # some slow clients might sometimes receive truncated data if last
>         # segment is lost and never retransmitted :
>         # option nolinger
>         option httpclose
>         option abortonclose
>         balance roundrobin
>         option forwardfor header remote-ip
>         retries 2
>         option redispatch
> 
> 
>         errorfile 400 /etc/haproxy/errors/400.http
>         errorfile 403 /etc/haproxy/errors/403.http
>         errorfile 408 /etc/haproxy/errors/408.http
>         errorfile 500 /etc/haproxy/errors/500.http
>         errorfile 502 /etc/haproxy/errors/502.http
>         errorfile 503 /etc/haproxy/errors/503.http
>         errorfile 504 /etc/haproxy/errors/504.http
> 
> ### HTTP ###
> 
> frontend fe:80
>         bind 127.0.0.1:80
>         acl debugme req.hdr_cnt(X-debug-me) ge 1
>         http-request lua mirror if debugme
>         default_backend be
> 
> frontend fe:443
>         bind 127.0.0.1:443 ssl crt /etc/ssl/private
>         default_backend be
> 
> backend be
>         server s1 127.0.0.2 
>         server s2 127.0.0.3
>         server s3 127.0.0.4
> 
> Regards,


-- 
Marc-Antoine

Reply via email to