-
hi, I met the issue that uWebSocket Crashed when I enable websocket compression. Not always, but occassionally. I hava already checked my string to compress when crashed. The string to compress is no problem. Please help me, thanks very much. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hello, If you look at the deepest part of your stack; start_thread and follow the stack up to where it crashes in deflate_fast you see that there is no call to us_loop_run. In other words, you are not sending from the thread that owns the socket. This library is strictly single threaded and needs one event-loop per thread, just like Node.js and similar. If you want to send from another thread you have to use us_wakeup_loop and send from the wakeup callback. However this incurs a few kernel calls and you also miss the fast path, since you need to buffer up the data somewhere until the wakeup callback can consume it. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. |
Beta Was this translation helpful? Give feedback.
-
Loop::defer(lambda) will call us_wakeup_loop and run that lambda on the thread which Loop is running on. That's the only place where you can send stuff.
You can get the Loop of a socket by us_socket_context, then us_socket_context_loop then convert that us_loop_t * to Loop * and defer. WebSocket<bool, bool> ptr is convertible to us_socket_t ptr. Then you get the us_loop_t ptr and convert that to a Loop ptr. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much again.
|
Beta Was this translation helpful? Give feedback.
-
hello, i has the same problem, i used another thread and user the: but the client cannot reveive msg, how can i solve this question. |
Beta Was this translation helpful? Give feedback.
Hello,
If you look at the deepest part of your stack; start_thread and follow the stack up to where it crashes in deflate_fast you see that there is no call to us_loop_run. In other words, you are not sending from the thread that owns the socket.
This library is strictly single threaded and needs one event-loop per thread, just like Node.js and similar. If you want to send from another thread you have to use us_wakeup_loop and send from the wakeup callback. However this incurs a few kernel calls and you also miss the fast path, since you need to buffer up the data somewhere until the wakeup callback can consume it.