[Libwebsockets] Tests and crashed

Andy Green andy at warmcat.com
Thu Mar 26 23:34:19 CET 2015



On 27 March 2015 00:49:31 GMT+08:00, Brice Hamon <brice at ydotm.com> wrote:
>Hi Andy,
>
>ok. Your call.  But IMO a API call should never crash a server.

Oh.  By the time of your second mail I missed the point it crashed the server.

Somehow I thought we were talking about it crashing the client.  Giving NULL to, eg strcmp() will do that.

In that case it is bad.

-Andy

>For the external event manager, cool. I will use that instead.
>
>Thanks again,
>
>Brice.
>
>
>On Thu, Mar 26, 2015 at 12:12 PM, Andy Green <andy at warmcat.com> wrote:
>
>>
>>
>> On 26 March 2015 21:44:37 GMT+08:00, Brice Hamon <brice at ydotm.com>
>wrote:
>> >Hi Andy,
>> >
>> >Thank you for your reply.
>> >
>> >A bad news and a good news.
>> >
>> >I start with the bad one:
>> >
>> >I reproduced it all the time with the test-server and the
>test-client
>> >with
>> >this modification:
>> >
>> >#if 0
>> >wsi_dumb = libwebsocket_client_connect(context, address, port,
>use_ssl,
>> >            "/", argv[optind], argv[optind],
>> >             protocols[PROTOCOL_DUMB_INCREMENT].name, ietf_version);
>> >#else
>> >wsi_dumb = libwebsocket_client_connect(context, address, port,
>use_ssl,
>> >            "/", "", NULL,
>>
>> ^^ That's not a problem that needs fixing... just don't set what's
>> required to be a string to NULL.
>>
>> >             protocols[PROTOCOL_DUMB_INCREMENT].name, ietf_version);
>> >#endif
>> >
>> >
>> >output from the server:
>> >
>> >lwsts[26940]:  Listening on port 7681
>> >    GET URI = /
>> >    key 1 = Upgrade
>> >    Upgrade = dumb-increment-protocol,fake-nonexistant-protocol
>> >    Origin = websocket
>> >    Version = vUKFq8/IRDmNxiJR8IYUBQ==
>> >    Sworigin = 13
>> >    Accept = x-webkit-deflate-frame,deflate-frame
>> >    Accept: = HTTP/1.1
>> >    Cookie: = no-cache
>> >    Content-Length: = no-cache
>> >*** glibc detected ***
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server:
>> >double free or corruption (top): 0x000000000063c8b0 ***
>> >Missing separate debuginfo for /lib64/libgcc_s.so.1
>> >Try: zypper install -C
>> >"debuginfo(build-id)=04626951231c50274a41cb283a3a41208ac47efe"
>> >======= Backtrace: =========
>> >/lib64/libc.so.6(+0x766d6)[0x7ffff6e406d6]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server[0x40e3fa]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server(libwebsocket_read+0x78)[0x410b28]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server[0x40eedd]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server(libwebsocket_service_fd+0x2ee)[0x406d3e]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server(lws_plat_service+0x78)[0x40d7a8]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server[0x404b59]
>> >/lib64/libc.so.6(__libc_start_main+0xed)[0x7ffff6deb23d]
>>
>>
>>/home/development/3rdparty/libwebsockets/build/bin/libwebsockets-test-server[0x404c95]
>> >
>> >
>> >(gdb) where
>> >#0  0x00007ffff6dfed95 in raise () from /lib64/libc.so.6
>> >#1  0x00007ffff6e002ab in abort () from /lib64/libc.so.6
>> >#2  0x00007ffff6e3a99e in __libc_message () from /lib64/libc.so.6
>> >#3  0x00007ffff6e406d6 in malloc_printerr () from /lib64/libc.so.6
>> >#4  0x000000000040e3fa in lws_handshake_server ()
>> >#5  0x0000000000410b28 in libwebsocket_read ()
>> >#6  0x000000000040eedd in lws_server_socket_service ()
>> >#7  0x0000000000406d3e in libwebsocket_service_fd ()
>> >#8  0x000000000040d7a8 in lws_plat_service ()
>> >#9  0x0000000000404b59 in main ()
>> >
>> >
>> >Ok for the good news:
>> >
>> >For the Windows crash,  you were correct. I had a problem in my code
>> >with
>> >the send buffers. Now fixed and working fine. :)
>>
>> Okie.
>>
>> >Just a quick question: can I have a external event manager on the
>> >client
>> >side (the same way I do it on the server side) ?
>>
>> I don't think it cares if it's serving or client... it just takes
>over the
>> poll business which is the same for both.
>>
>> -Andy
>>
>> >Thank you,
>> >
>> >Brice.
>> >
>> >
>> >On Wed, Mar 25, 2015 at 7:55 PM, Andy Green <andy at warmcat.com>
>wrote:
>> >
>> >>
>> >>
>> >> On 25 March 2015 22:23:37 GMT+08:00, Brice Hamon <brice at ydotm.com>
>> >wrote:
>> >> >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.
>> >>
>> >> Sounds good.
>> >>
>> >> >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:
>> >>
>> >> Ugh that sounds bad.
>> >>
>> >> However, I cannot reproduce it with the test client + server.
>> >>
>> >> This should do it, right?
>> >>
>> >> diff --git a/test-server/test-client.c b/test-server/test-client.c
>> >> index e94dbed..d48cf7f 100644
>> >> --- a/test-server/test-client.c
>> >> +++ b/test-server/test-client.c
>> >> @@ -337,7 +337,7 @@ int main(int argc, char **argv)
>> >>         /* create a client websocket using dumb increment protocol
>*/
>> >>
>> >>         wsi_dumb = libwebsocket_client_connect(context, address,
>> >port,
>> >> use_ssl,
>> >> -                       "/", argv[optind], argv[optind],
>> >> +                       "/", "", "", //argv[optind], argv[optind],
>> >>                          protocols[PROTOCOL_DUMB_INCREMENT].name,
>> >> ietf_version);
>> >>
>> >>         if (wsi_dumb == NULL) {
>> >>
>> >> >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
>> >>
>> >> [agreen at build build]$ libwebsockets-test-client localhost
>> >> libwebsockets test client
>> >> (C) Copyright 2010-2013 Andy Green <andy at warmcat.com> licensed
>under
>> >> LGPL2.1
>> >> [1427327038:4868] NOTICE: Initial logging level 7
>> >> [1427327038:4868] NOTICE: Library version: 1.3 1677ca5
>> >> [1427327038:4868] NOTICE: IPV6 not compiled in
>> >> [1427327038:4868] NOTICE: libev support not compiled in
>> >> [1427327038:4869] NOTICE:  static allocation: 4536 + (16 x 1024
>fds)
>> >=
>> >> 20920 bytes
>> >> [1427327038:4869] NOTICE:  canonical_hostname = build.warmcat.com
>> >> [1427327038:4869] NOTICE:  per-conn mem: 248 + 2140 headers +
>> >protocol rx
>> >> buf
>> >> Waiting for connect...
>> >> [1427327038:5041] WARN: problems parsing header
>> >> Exiting
>> >> [1427327038:5042] NOTICE: libwebsocket_context_destroy
>> >> LWS_CALLBACK_CLIENT_CONNECTION_ERROR
>> >>
>> >> He acts the same with --ssl
>> >>
>> >> >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.
>> >>
>> >> I guess something real is happening but I can't casually reproduce
>> >it.
>> >>
>> >> It's doesn't necessarily follow, but often that means it's
>something
>> >in
>> >> your code.
>> >>
>> >> >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);
>> >>
>> >> Hm.
>> >>
>> >> Actually if I were you I would look for the same problems in the
>test
>> >> server + client.  If you can reproduce them there, it's much
>easier
>> >for me
>> >> to join you in looking at it.
>> >>
>> >> If the test apps work fine, it suggests (but it doesn't definitely
>> >> mean...) the problem might be in your adaptations.
>> >>
>> >> -Andy
>> >>
>> >> >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.
>> >> >
>> >> >
>> >>
>>
>>>------------------------------------------------------------------------
>> >> >
>> >> >_______________________________________________
>> >> >Libwebsockets mailing list
>> >> >Libwebsockets at ml.libwebsockets.org
>> >> >http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>> >>
>> >>
>>
>>




More information about the Libwebsockets mailing list