[uWSGI] websocket psgi sharedarea_wait broken?

Roberto De Ioris roberto at unbit.it
Tue Apr 29 16:04:03 CEST 2014


> Am 29.04.2014 11:17, schrieb Roberto De Ioris:
>>> Am 28.04.2014 21:28, schrieb Roberto De Ioris:
>>>>> hi,
>>>>>
>>>>> my first post here ;)
>>>>>
>>>>> PSGI (looks similar to the eyetoy example, but does not work for me):
>>>>> ...
>>>>> uwsgi::websocket_handshake($env->{HTTP_SEC_WEBSOCKET_KEY},
>>>>> $env->{HTTP_ORIGIN});
>>>>>
>>>>> while(1) {
>>>>>
>>>>>      # wait for updates in the sharedarea
>>>>>      uwsgi::sharedarea_wait(0, 50); # this is line 70
>>>>>      # send a binary websocket message directly from the sharedarea
>>>>>      uwsgi::websocket_send_from_sharedarea(0, 0);
>>>>> }
>>>>>
>>>>> INI
>>>>> [uwsgi]
>>>>> plugins         = http,0:psgi,coroae
>>>>> psgi            = /path/to/my.psgi
>>>>> http-socket     = :8080
>>>>> master          = true
>>>>> coroae          = 40
>>>>> http-websockets = true
>>>>> sharedarea      = 1
>>>>> uid             = www-data
>>>>> gid             = www-data
>>>>>
>>>>> testing uwsgi 2.0.3 and 2.0.4, both fail with:
>>>>>
>>>>> [uwsgi-perl error] FATAL: Coro SLF calls can only be made normally,
>>>>> not
>>>>> via goto or any other means, caught at ... line 70.
>>>>> -> multiple times
>>>>> *** Error in `./uwsgi': realloc(): invalid next size:
>>>>> 0x00000000018ee7c0
>>>>> ***
>>>>> !!! uWSGI process 3635 got Segmentation Fault !!!
>>>>>
>>>>> perl -v
>>>>> This is perl 5, version 18, subversion 2 (v5.18.2) built for
>>>>> x86_64-linux-gnu-thread-multi
>>>>>
>>>>> libcoro-perl
>>>>> Version: 6.370-1
>>>>>
>>>>> debian wheezy, virtualbox
>>>>>
>>>> Need to check it, but in the mean time can you try with latest
>>>> coro::anyevent package ? (from sources)
>>>>
>>>>
>>>>
>>>>
>>> coro::anyevent 6.37 (04.03.2014) is the latest available package showed
>>> by cpan...
>>> no clue where to find nightly builds or something similar...
>>>
>>>
>>>
>>
>> Unfortunately that error pop-up when libev engine is loaded in coro
>> (Coro::EV). I did not understand why it is triggered but i was able to
>> fake it calling Coro::AnyEvent::sleep using perl_eval_pv:
>>
>> https://github.com/unbit/uwsgi/blob/master/plugins/coroae/coroae.c#L68
>>
>> definitely not a great way, but it should work
>>
>> Let me know
>
> yes, that solved the problem.
>
> but i ask myself if using sharedarea_wait() with
> websocket_send_from_sharedarea()
> is the only way for broadcasting data to all listeners.
>
> your eyetoy example looks ideal to this method.
> but a simple chat (single user sends message to all listeners) seems
> much more difficult to me than i expected.
>
> i'll keep trying...
>
> kind regards
> alex
>

There is no such thing as "listeners" in uWSGI, as a connection can be
mapped to a thread, a process or a greenthread (and all must be supported
out of the box). For such a reason the pub/sub redis system is the best
approach (at least for me):

https://github.com/unbit/uwsgi/blob/master/tests/websockets_chat.pl

(this example uses AnyEvent, if you use processes things are way easier)

-- 
Roberto De Ioris
http://unbit.it


More information about the uWSGI mailing list