5

I have been trying to run the websocket chat example provided here on an Apple Mac. https://github.com/unbit/uwsgi/blob/master/tests/websockets_chat_async.py

But running this example results in a segfault in uwsgi.

I have copied pasted this example in websocket.py and am running the server with the following command

uwsgi --http :8080 --http-websockets --wsgi-file websocket.py --venv ../../python2-wow

When I access the URL, I get the proper message for connection establishing. But then the server crashes with this segfault

!!! uWSGI process 29129 got Segmentation Fault !!!
*** backtrace of 29129 ***
0   uwsgi                               0x00000001078b5ec0 uwsgi_backtrace + 48
1   uwsgi                               0x00000001078b6371 uwsgi_segfault + 49
2   libsystem_platform.dylib            0x00007fff96b2c5aa _sigtramp + 26
3   ???                                 0x0000000000000000 0x0 + 0
4   uwsgi                               0x0000000107897b4e async_add_fd_read + 206
5   uwsgi                               0x00000001078c8979 py_eventfd_read + 89
6   Python                              0x00000001079d214d PyEval_EvalFrameEx + 8080
7   Python                              0x00000001079d0093 PyEval_EvalCodeEx + 1641
8   Python                              0x0000000107977796 PyFunction_SetClosure + 809
9   Python                              0x0000000107959f72 PyObject_Call + 101
10  Python                              0x00000001079d601f PyEval_CallObjectWithKeywords + 93
11  uwsgi                               0x00000001078c6dc7 python_call + 23
12  uwsgi                               0x00000001078c8df9 uwsgi_request_wsgi + 889
13  uwsgi                               0x000000010787b7e3 wsgi_req_recv + 291
14  uwsgi                               0x00000001078b38a5 simple_loop_run + 229
15  uwsgi                               0x00000001078ba6e2 uwsgi_ignition + 226
16  uwsgi                               0x00000001078ba5ae uwsgi_worker_run + 670
17  uwsgi                               0x00000001078b9d26 uwsgi_start + 5078
18  uwsgi                               0x00000001078b81a3 main + 7331
19  libdyld.dylib                       0x00007fff8c6ce5fd start + 1
*** end of backtrace ***

Apparantly the crash is on this line

uwsgi.wait_fd_read(websocket_fd, 3)

Stumped here. Need help.

remudada
  • 3,751
  • 2
  • 33
  • 60
  • 2
    You're missing --async option – jwalker Jan 21 '14 at 14:37
  • @jwalker tried --async option but still have the same crash. . . – remudada Jan 21 '14 at 15:12
  • 2
    Not sure if you need --http-websockets. Also make sure you have latest uWSGI. – jwalker Jan 21 '14 at 15:28
  • jwalker removing --http-websockets has little effect on the end result. Also, I did not initially mention that I was running this on a Mac. Maybe this has something to do with that. Updated the question to reflect that information as well – remudada Jan 21 '14 at 16:47
  • 2
    Ok, I tried running it, and found that apparently it needs --ugreen. But still although I got no more errors, it didn't really work. Perhaps this native async mode is outdated, and you should use newer gevent-based approach. – jwalker Jan 21 '14 at 19:09
  • 2
    ugreen/swapcontext does not work anymore on osx (apple broke it a couple of versions ago), so on the mac you are limited to gevent (or greenlet, or classic threads) – roberto Jan 22 '14 at 05:33
  • 2
    @roberto I ran it on Ubuntu, but it didn't work (although I got no errors). I also tried greenlet mode, but uWSGI didn't recognize that I suppose (got error that async was used without coroutine engine). – jwalker Jan 22 '14 at 19:18
  • Is there no sample to get async websocket working on uWSGI 2.0? – remudada Jan 24 '14 at 16:44
  • It didn't work for me because of older nginx. Made it an answer. – jwalker Jan 24 '14 at 22:08

1 Answers1

1

I made it to work with --async=100 and --ugreen options.

Note that there are newer API's that you can use: native WebSocket support and generic gevent-based async support.

jwalker
  • 1,999
  • 16
  • 27