[Libwebsockets] Detect multiple server run

Andy Green andy at warmcat.com
Thu Nov 22 11:35:57 CET 2018



On 22/11/2018 02:56, Andy Green wrote:
> 
> 
> On November 21, 2018 10:39:10 PM GMT+08:00, Stefano Mora <stefano.mora at newdep.com> wrote:
>> Hello everyone,
>> I'd like to know if it is possible to detect multiple run of the same
>> server.
>> My initial guess was that the context parameter should be null, but it
>> is not.
>> If I run the server twice I see on the console the following:
>>
>> [2018/11/21 15:34:36:8536] USER: Visit http://localhost:7681
>> [2018/11/21 15:34:36:8537] ERR: 11
>> [2018/11/21 15:34:36:8540] NOTICE: Creating Vhost 'default' port 7681,
>> 2 protocols, IPv6 off
>> [2018/11/21 15:34:36:8542] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:36:8543] ERR: VH default: iface (null) port 7681
>> DOESN'T EXIST
>> [2018/11/21 15:34:36:8545] ERR: 22 2140495960
>> [2018/11/21 15:34:36:8545] ERR: 33
>> [2018/11/21 15:34:36:8547] USER: LWS_INIT
>> [2018/11/21 15:34:36:8548] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:36:8549] USER: !! callback reason: 71
>> [2018/11/21 15:34:37:8553] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:38:8566] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:39:8578] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:40:8583] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
>> [2018/11/21 15:34:41:8595] ERR: ERROR on binding fd 6 to port 7681 (-1
>> 98)
> 
> This is intended to be a feature rather than a bug... per-vhost, if it encounters that it cannot create the vhost listening socket, it will retry in the background with any successful vhosts operational.  You can see the 'feature' part by recreating the situation and then killing the original process... the second process will succeed to create its listen socket next retry and then continue without further complaints, operational on the vhost with the deferred init.
> 
> It's actually aimed at the case the network interface doesn't exist yet, not at -EADDRINUSE (98).  If no objections, I think we can actually just make -EADDRINUSE fatal.

I pushed a patch on master that does this.

-Andy

> -Andy
> 
>> My code is:
>> lwsl_err("11\n");
>>         engineData.context = lws_create_context(&info);
>> lwsl_err("22 %d\n", engineData.context);
>>         if (engineData.context==0) {
>>                 lwsl_err("lws init failed\n");
>>                 return 1;
>>         }
>> lwsl_err("33\n");
>>
>> How can I catch the initial problem and gently exit?
>>
>> Thanks,
>> regards
>> ---
>> Stefano Mora / SW Engineer
>> stefano.mora at newdep.com<mailto:stefano.mora at newdep.com>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list