wolkykim / libasyncd

Libasyncd is an embeddable event-based asynchronous Message/HTTP server framework for C/C++.

Home Page:http://wolkykim.github.io/libasyncd/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segfault when using OpenSSL with HTTP handler

dtoubelis opened this issue · comments

I'm getting a segfault when using SSL mode. Here is a trace from gdb:

...
[DEBUG] conn_cb: status:0x0, event:0x4 [conn_cb(),ad_server.c:724]
[DEBUG] call_hooks: event 0x4 [call_hooks(),ad_server.c:758]
[DEBUG] ==> HTTP WRITE [ad_http_handler(),ad_http_handler.c:101]
[DEBUG] call_hooks: event 0x8 [call_hooks(),ad_server.c:758]
[DEBUG] ==> HTTP CLOSE=8 (TIMEOUT=0, SHUTDOWN=0) [ad_http_handler(),ad_http_handler.c:105]
[DEBUG] Connection closed. [conn_cb(),ad_server.c:751]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb3fff700 (LWP 21411)]
0x00007ffff672e9e6 in evbuffer_get_length () from /usr/lib/libevent-2.0.so.5
(gdb) bt
#0  0x00007ffff672e9e6 in evbuffer_get_length () from /usr/lib/libevent-2.0.so.5
#1  0x0000000000421dbc in ad_http_send_header (conn=<optimized out>) at ad_http_handler.c:345
#2  0x0000000000422078 in ad_http_send_data (conn=0x7fffac006160, data=0x42b17a, size=11) at ad_http_handler.c:367
#3  0x000000000040d51f in _http_get_handler (event=2, conn=0x7fffac006160, userdata=0x0) at ak-http-connector.c:80
#4  0x000000000041f6f6 in call_hooks (event=2, conn=0x7fffac006160) at ad_server.c:769
#5  0x00000000004204ec in conn_cb (conn=0x7fffac006160, event=2) at ad_server.c:726
#6  0x00007ffff6963369 in ?? () from /usr/lib/libevent_openssl-2.0.so.5
#7  0x00007ffff696397a in ?? () from /usr/lib/libevent_openssl-2.0.so.5
#8  0x00007ffff6963a08 in ?? () from /usr/lib/libevent_openssl-2.0.so.5
#9  0x00007ffff67299cc in event_base_loop () from /usr/lib/libevent-2.0.so.5
#10 0x000000000041f5b1 in server_loop (instance=0x650700) at ad_server.c:511
#11 0x00007ffff6145e9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#12 0x00007ffff644e8bd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#13 0x0000000000000000 in ?? ()

The test program is the one from README.md with minor tweaks to SSL_CTX_*. The code is executed on Ubuntu 12.04. And requests are generated from https://www.ssllabs.com/ssltest/index.html.

Any ideas?

This error occurs in different places on different runs and it looks like the connection object is being closed or freed in a different thread. I'm not sure why this would be possible if the server is single threaded, but I do not see any other explanation.

Thank you for the patch.