[Libwebsockets] lws + libuv ( mac/freebsd ), explicit_vhosts

Aleksey Zhukovskiy beetle at gambler.ru
Tue Nov 29 11:57:12 CET 2016


Seems to initialization of all vhosts takes place in lws_uv_initloop()
(module libuv.c) at while( vh ) { ... }
So if I create vhost later, then I have empty field w_read which needs for
libuv operations.
no callback when creating wsi of new vhost?

2016-11-29 12:44 GMT+02:00 Aleksey Zhukovskiy <beetle at gambler.ru>:

> I just want to say that on *FreeBSD*, *libdl* is part of libc, so if you
> add libdl for unix (CMakeLists.txt)
>         if (UNIX AND LWS_WITH_PLUGINS)
>                 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
>                target_link_libraries(websockets dl)
>         endif()
> when linking C executable bin/libwebsockets-test-fraggle we face error
> "cannot find -ldl" and can't finish make process. This may be a unnecessary
> disapointment for some freebsd users.
> maybe better to patch contition to
>         if (UNIX AND LWS_WITH_PLUGINS AND NOT( ${CMAKE_SYSTEM_NAME}
> MATCHES "FreeBSD" ))
> because Im not sure about entire BSD-family
>
> I built debug versions of libuv and libwebsockets and still debug it. Hope
> to send you some interesting a little bit later.
> Know exactly that segfault occurs in libuv because loop==NULL in handle.
> It occurs because wsi->w_read is not initialized (fully zeroed). I didn't
> find initialization block already.
>
> 2016-11-29 12:01 GMT+02:00 Andy Green <andy at warmcat.com>:
>
>> On Tue, 2016-11-29 at 11:31 +0200, Aleksey Zhukovskiy wrote:
>> > First thing I found when trying lwsws on freebsd - error at linking.
>> > Freebsd does not have libdl (included in std), CMakeLists.txt doesn't
>>
>> Mmm the plugins are handled by libuv.  There's an old dl implementation
>> lurking around to keep Travis happy, which has ancient libuv by default
>> that has no dl support.  It's just there to make it build if the libuv
>> is too old.
>>
>> Somehow you are building this junk libdl implementation not the libuv-
>> specific one.
>>
>> > have to add target_link_libraries(websockets dl). This occured when I
>> > activated lwsws and it follows LWS_WITH_PLUGINS. Simply commenting
>> > this line solved the problem.
>>
>> I don't think it solved the problem... killing plugins hid the symptom.
>>
>> The old dl stuff lives in ./lib/lws-plat-unix, and is protected like
>> this
>>
>> #ifdef LWS_WITH_PLUGINS
>>
>> #if defined(LWS_USE_LIBUV) && UV_VERSION_MAJOR > 0
>>
>> /* libuv.c implements these in a cross-platform way */
>>
>> #else
>>
>> ... the old, dummy implementation
>>
>> #endif
>>
>> So something is wrong either with LWS_USE_LIBUV or UV_VERSION_MAJOR on
>> your system.  On Travis with the ancient libuv, UV_VERSION_MAJOR is 0,
>> so it uses this placeholder libdl code.  But on a system with recent
>> libuv, that should never happen and there is no direct dependency on
>> libdl (on Linux, libuv wants libdl.  I dunno what libuv does on BSD for
>> dynamic linking type operations but assuming BSD has that concept, it
>> should have a suitable implementation using the generic libuv api).
>>
>> > After some time my testing pointed to core of problem: I can not add
>> > vhost just after initializing libuv loop. If I add vhost before it
>> > all is ok. Howewer its important to me  to have this possibility. I
>> > can start listen for some ports when only another instance of my
>> > daemon frees it. So maybe is there some way to initialize but "sleep"
>> > some vhost? Then I can create it before main cycle. Or maybe its
>> > better to provide feature of adding vhost on working loop.
>>
>> I don't see why anything cares.  Lws should not care how late it is to
>> the party after the loop starts.  In fact it supports "foreign loops"
>> that exist completely outside lws, and can have done whatever before
>> lws even starts up.
>>
>> Actually your backtrace is saying that **libuv** cares, it blows up
>> inside libuv when handling what looks to be a socket fd.  You will need
>> to add debuginfo or whatever the bsd equivalent is to libuv, so gdb can
>> show us exactly where he chokes in libuv and we can get a clue about
>> why.
>>
>> > How do you do hot reload of configuration of lwsws without restart if
>> > added new listening ports in config?
>>
>> That concept doesn't exist in lws... vhosts are created one time after
>> the contexts are created.  For my usecases, that has always been fine,
>> I just restart the service.
>>
>> Patches are always welcome though... it should be easy to add vhosts
>> randomly but I am not sure how cleanly you can kill a vhost is it's
>> happening with the rest of the system staying up.
>>
>> -Andy
>>
>> >
>> >
>> > 2016-11-28 23:31 GMT+02:00 Andy Green <andy at warmcat.com>:
>> > >
>> > > On November 29, 2016 4:42:02 AM GMT+08:00, Aleksey Zhukovskiy <beet
>> > > le at gambler.ru> wrote:
>> > > >Andy,
>> > > >thanx for answers, thats what I thought about libuv. My version of
>> > > it
>> > > >is
>> > > >1.10 (seems ok?)
>> > >
>> > > Yes.
>> > >
>> > > If you run the libuv test server instead of your code, is it still
>> > > broken?
>> > >
>> > > https://github.com/warmcat/libwebsockets/blob/master/test-server/te
>> > > st-server-libuv.c
>> > >
>> > > How about if you run lwsws?
>> > >
>> > > https://github.com/warmcat/libwebsockets/blob/master/README.lwsws.m
>> > > d
>> > >
>> > > Both of these implement lws + libuv and don't crash here... if they
>> > > don't crash for you either it looks like you might not be initing
>> > > the libuv loop correctly in you code.  If they do crash, can you
>> > > install debuginfo for libuv so we can see more detail?
>> > >
>> > > If all you want is a generic server with your own protocols you can
>> > > use lwsws out of the box with no code changes, configuring it with
>> > > JSON (eg, multiple vhosts) and making your protocol a standalone
>> > > plugin
>> > >
>> > > https://github.com/warmcat/libwebsockets/tree/master/plugin-standal
>> > > one
>> > >
>> > > This model is serving https://libwebsockets.org +
>> > > https://warmcat.com , eg the test ws server is done entirely with
>> > > protocol plugins... this is much cleaner, eg
>> > >
>> > > https://github.com/warmcat/libwebsockets/blob/master/plugins/protoc
>> > > ol_dumb_increment.c
>> > >
>> > > -Andy
>> > >
>> > > >I made new tests. I've switched off SSL, excess protocols, all
>> > > >extensions.
>> > > >I do not make some connects now, dont create vhosts. I've
>> > > simplified
>> > > >all
>> > > >names and parameters. I've built libws with switching off some
>> > > >extra-parameters.
>> > > >And I am still crashing.  At first call to
>> > > >lws_create_vhost( lwscontext, &info )  - gdb backtrace is the same
>> > > I
>> > > >sent
>> > > >This is dump of libwebsockets (freebsd, Apple is the same)
>> > > >
>> > > >[2016/11/28 22:28:27:2159] NOTICE: Initial logging level 7
>> > > >[2016/11/28 22:28:27:2159] NOTICE: Libwebsockets version: 2.1.0
>> > > >beetle at B10.1-v2.0.0-188-ge67dfe1
>> > > >[2016/11/28 22:28:27:2159] NOTICE: IPV6 not compiled in
>> > > >[2016/11/28 22:28:27:2159] NOTICE: libev support not compiled in
>> > > >[2016/11/28 22:28:27:2159] NOTICE: libuv support compiled in and
>> > > >enabled
>> > > >[2016/11/28 22:28:27:2160] NOTICE:  Threads: 1 each 13950 fds
>> > > >[2016/11/28 22:28:27:2161] NOTICE:  mem: platform fd map: 111600
>> > > bytes
>> > > >[2016/11/28 22:28:27:2161] NOTICE:  Compiled with OpenSSL support
>> > > >[2016/11/28 22:28:27:2161] NOTICE:  SSL disabled: no
>> > > >LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
>> > > >[2016/11/28 22:28:27:2161] NOTICE:  mem: per-conn:          688
>> > > bytes +
>> > > >protocol rx buf
>> > > >[2016/11/28 22:28:27:2161] NOTICE:  canonical_hostname = B10.1
>> > > >[2016/11/28 22:28:27:2162] NOTICE: Creating Vhost 'localhost' port
>> > > >60000, 1
>> > > >protocols, IPv6 off
>> > > >
>> > > >After clearing LWS_SERVER_OPTION_EXPLICIT_VHOSTS added two lines
>> > > >[2016/11/28 22:29:40:3383] NOTICE: Creating Vhost 'default' port
>> > > 0, 1
>> > > >protocols, IPv6 off
>> > > >[2016/11/28 22:29:40:3400] NOTICE:  Listening on port 60815
>> > > >
>> > > >but finally segfault catched us. Seems to be my vhost has some
>> > > problem.
>> > > >"Segfaulty" problem.
>> > > >at this moment I have no more time for experiments, tomorrow will
>> > > try
>> > > >to
>> > > >continue
>> > > >
>> > > >
>> > > >2016-11-27 23:45 GMT+02:00 Andy Green <andy at warmcat.com>:
>> > > >
>> > > >>
>> > > >>
>> > > >> On November 28, 2016 4:22:52 AM GMT+08:00, Andy Green
>> > > ><andy at warmcat.com>
>> > > >> wrote:
>> > > >> >
>> > > >> >
>> > > >> >On November 28, 2016 1:26:18 AM GMT+08:00, Aleksey Zhukovskiy
>> > > >> ><beetle at gambler.ru> wrote:
>> > > >>
>> > > >> >>1. It there a reason to use libuv/ev for better perfomance at
>> > > all?
>> > > >> >
>> > > >> >Yes, it will use epoll() rather than poll().  If you have many
>> > > >> >connections, this is faster.
>> > > >>
>> > > >> Well, on bsd, kqueue.  Basically libuv has backends for the best
>> > > >native
>> > > >> event wait on the platform and converts to generic libuv events.
>> > > >>
>> > > >> -Andy
>> > > >>
>> > > >>
>> > >
>> > >
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20161129/868194f2/attachment-0001.html>


More information about the Libwebsockets mailing list