[Libwebsockets] Tests and crashed

Brice Hamon brice at ydotm.com
Wed Mar 25 15:23:37 CET 2015


Hi guys,

I have a C++ linux WS server running great with any browser over wss://

I am using Library version: 1.3 8721f4f and gcc (SUSE Linux) 4.6.2.

I wanted to create a test suite with the client api.

I noticed 2 things:

First:

The linux client API works great. When I connect I get:

15-03-25 10:07:30.059884 INFO : [BSWEBSOCKET  ]: Received network connect
from localhost (::1)
15-03-25 10:07:30.059976 DEBUG: [BSWEBSOCKET  ]: libwebsocket:
insert_wsi_socket_into_fds: wsi=0x7fffc00052f0, sock=59, fds pos=3
15-03-25 10:07:30.060035 DEBUG: [BSWEBSOCKET  ]: libwebsocket: inserted SSL
accept into fds, trying SSL_accept
15-03-25 10:07:30.060198 DEBUG: [BSWEBSOCKET  ]: libwebsocket:
SSL_ERROR_WANT_READ
15-03-25 10:07:30.061246 DEBUG: [BSWEBSOCKET  ]: libwebsocket:
SSL_ERROR_WANT_READ
15-03-25 10:07:30.090249 DEBUG: [BSWEBSOCKET  ]: libwebsocket: checking
bsws-protocol
15-03-25 10:07:30.090281 DEBUG: [BSWEBSOCKET  ]: libwebsocket: prot match 1
15-03-25 10:07:30.090677 INFO : [BSWEBSOCKET  ]: bsws protocol: websocket
request from localhost (::1)
15-03-25 10:07:30.090725 DEBUG: [BSWEBSOCKET  ]: callback_http:
LWS_CALLBACK_CONFIRM_EXTENSION_OKAY for protocol [x-webkit-deflate-frame]
15-03-25 10:07:30.090780 DEBUG: [BSWEBSOCKET  ]: callback_http:
LWS_CALLBACK_CONFIRM_EXTENSION_OKAY for protocol [deflate-frame]
15-03-25 10:07:30.091027 INFO : [BSWEBSOCKET  ]: callback_bsws: websocket
established for pss=0x7fffc000a120, wsi=0x7fffc00052f0
15-03-25 10:07:30.091057 DEBUG: [BSWEBSOCKET  ]: libwebsocket: Allocating
RX buffer 102422

Now If I don't specify a host in the call:

wsi= libwebsocket_client_connect(context, address.c_str(), port, use_ssl,
            "/", "", "",
             protocols[PROTOCOL_BSWS].name, ietf_version);

I crashed the server in:

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffd23fc700 (LWP 5609)]
0x00007ffff4f47d95 in raise () from /lib64/libc.so.6
(gdb) where
#0  0x00007ffff4f47d95 in raise () from /lib64/libc.so.6
#1  0x00007ffff4f492ab in abort () from /lib64/libc.so.6
#2  0x00007ffff4f8399e in __libc_message () from /lib64/libc.so.6
#3  0x00007ffff4f896d6 in malloc_printerr () from /lib64/libc.so.6
#4  0x00007ffff72cdb6e in lws_handshake_server ()
   from /export/home/development/3rdparty/lib/libwebsockets.so.5.0.0
#5  0x00007ffff72c4238 in libwebsocket_read ()
   from /export/home/development/3rdparty/lib/libwebsockets.so.5.0.0
#6  0x00007ffff72ce67f in lws_server_socket_service ()
   from /export/home/development/3rdparty/lib/libwebsockets.so.5.0.0
#7  0x00007ffff72c58fe in libwebsocket_service_fd ()
   from /export/home/development/3rdparty/lib/libwebsockets.so.5.0.0
#8  0x0000000000448dba in BS::BSWebSocket::processUserEvent (this=0x66d730,
ptr=0x7fffc0003a30,
    event=1) at bswebsocket.cpp:279

I traced the cause and it appears that I am getting called twice for an
even on the WS file descriptor which causes the libwebsocket to abort.

My logs are when this happen:
15-03-25 10:10:11.673659 INFO : [BSWEBSOCKET  ]: Received network connect
from localhost (::1)

15-03-25 10:10:11.674253 DEBUG: [BSWEBSOCKET  ]: libwebsocket:
insert_wsi_socket_into_fds: wsi=0x7fffc000d900, sock=59, fds pos=2

15-03-25 10:10:11.674663 DEBUG: [BSWEBSOCKET  ]: libwebsocket: inserted SSL
accept into fds, trying SSL_accept

15-03-25 10:10:11.676141 DEBUG: [BSWEBSOCKET  ]: libwebsocket:
SSL_ERROR_WANT_READ

15-03-25 10:10:11.710140 DEBUG: [BSWEBSOCKET  ]: libwebsocket: checking
bsws-protocol

15-03-25 10:10:11.710487 DEBUG: [BSWEBSOCKET  ]: libwebsocket: prot match 1

15-03-25 10:10:11.711067 INFO : [BSWEBSOCKET  ]: bsws protocol: websocket
request from localhost (::1)
15-03-25 10:10:11.711299 DEBUG: [BSWEBSOCKET  ]: libwebsocket: hs0405 has
failed the connection

*** glibc detected *** /home/user/work/src/servers/bswebhttp/bswebhttp:
double free or corruption (out): 0x00007fffc0010690 ***

I want to prevent such crash if possible.

Second:

My second and most important problem is that the same code (working on
linux) compiled on Windows MSVC2010 does not work.
It connects to the server successfully, but then dies here:

extension-deflate-frame.c line 244
conn->buf_out = lws_realloc(conn->buf_out,
    LWS_SEND_BUFFER_PRE_PADDING +
    conn->buf_out_length +
    LWS_SEND_BUFFER_POST_PADDING);

from the stack:
  ntdll.dll!772a25df()
  zlib1.dll!62e8d02f()
> msvcr100d.dll!_realloc_base(void * pBlock, unsigned int newsize)  Line 85
+ 0x17 bytes C
  msvcr100d.dll!realloc_help(void * pUserData, unsigned int * pnNewSize,
int nBlockUse, const char * szFileName, int nLine, int fRealloc)  Line 832
+ 0x10 bytes C++
  msvcr100d.dll!_realloc_dbg(void * pUserData, unsigned int nNewSize, int
nBlockUse, const char * szFileName, int nLine)  Line 1040 + 0x1b bytes C++
  msvcr100d.dll!realloc(void * pUserData, unsigned int nNewSize)  Line 60 +
0x13 bytes C++
  websockets.dll!_realloc(void * ptr, unsigned int size)  Line 6 + 0x10
bytes C
  websockets.dll!lws_realloc(void * ptr, unsigned int size)  Line 16 + 0x10
bytes C
  websockets.dll!lws_extension_callback_deflate_frame(libwebsocket_context
* context, libwebsocket_extension * ext, libwebsocket * wsi,
libwebsocket_extension_callback_reasons reason, void * user, void * in,
unsigned int len)  Line 244 + 0x19 bytes C
  websockets.dll!lws_ext_callback_for_each_active(libwebsocket * wsi, int
reason, void * arg, int len)  Line 57 + 0x40 bytes C
  websockets.dll!libwebsocket_write(libwebsocket * wsi, unsigned char *
buf, unsigned int len, libwebsocket_write_protocol protocol)  Line 297 +
0x11 bytes C
  wsclient.exe!websocket_write(libwebsocket * wsi, const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > * msg)
 Line 65 + 0x16 bytes C++
  wsclient.exe!callback_bsws(libwebsocket_context * context, libwebsocket *
wsi, libwebsocket_callback_reasons reason, void * user, void * in, unsigned
int len)  Line 309 + 0xd bytes C++
  websockets.dll!user_callback_handle_rxflow(int (libwebsocket_context *,
libwebsocket *, libwebsocket_callback_reasons, void *, void *, unsigned
int)* callback_function, libwebsocket_context * context, libwebsocket *
wsi, libwebsocket_callback_reasons reason, void * user, void * in, unsigned
int len)  Line 619 + 0x1d bytes C
  websockets.dll!lws_calllback_as_writeable(libwebsocket_context * context,
libwebsocket * wsi)  Line 44 + 0x25 bytes C
  websockets.dll!lws_handle_POLLOUT_event(libwebsocket_context * context,
libwebsocket * wsi, libwebsocket_pollfd * pollfd)  Line 261 + 0xd bytes C
  websockets.dll!libwebsocket_service_fd(libwebsocket_context * context,
libwebsocket_pollfd * pollfd)  Line 483 + 0x4d bytes C
  websockets.dll!lws_plat_service(libwebsocket_context * context, int
timeout_ms)  Line 163 + 0xd bytes C
  websockets.dll!libwebsocket_service(libwebsocket_context * context, int
timeout_ms)  Line 634 + 0xd bytes C
  wsclient.exe!main(int argc, char * * argv)  Line 466 + 0xb bytes C++
  wsclient.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes C
  wsclient.exe!mainCRTStartup()  Line 371 C

Before I dig more into the code, is there anything obvious I am doing wrong
here ?

Thank you,

Brice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20150325/b3ab3b13/attachment.html>


More information about the Libwebsockets mailing list