digitalmars.D - Vibe.d WebSockets crashing the thread
- a (16/16) Mar 22 2019 I am working on a project (multiplayer browser-based game) that
- Sebastiaan Koppe (6/13) Mar 22 2019 I don't think it is safe to pass a vibe-d Websocket to another
- a (3/18) Mar 22 2019 Hm, I might have to do that. But would that explain why is works
- Sebastiaan Koppe (4/8) Mar 22 2019 What I forgot to mention is that you are calling methods on the
- a (3/11) Mar 22 2019 I tried getting rid of the function calls in the vibe.d thread,
- Benjamin Schaaf (4/17) Mar 24 2019 Not sure about WebSockets, but vibe.d often has the requirement
- arakan arkino (3/22) Apr 20 2019 I tried getting rid of the function calls in the vibe.d thread,
- Benjamin Schaaf (3/5) Apr 20 2019 Could you post your new code, that will probably narrow it down
- a (3/18) Mar 22 2019 Also, sending data _to_ the websocket from the 2nd thread works
I am working on a project (multiplayer browser-based game) that uses websockets. I structured the project so that there are 2 threads: one of them is the vibe.d web server, and the other is the actual server for the game itself. Because of this structure, I am passing WebSockets from the webserver to the game server using std.concurrency.send. This seems to barely work though, and it is really unreliable (crashes after a few seconds). Sometimes it gives and error about core.exception.AssertError ../../.dub/packages/vibe-core-1.6.1/vibe-core/source/v be/core/net.d(593): Assertion failure, but other times it just simply stops receiving messages from the websocket (I think this is because the game-server thread may be crashing, but I'm not sure). Here is some minimal code that reproduces the issue: source/app.d: http://dpaste.com/2QCSXC1 and public/index.html: http://dpaste.com/02QANJY I would really appreciate if anyone could help me fix this. Thanks!
Mar 22 2019
On Friday, 22 March 2019 at 20:23:05 UTC, a wrote:Here is some minimal code that reproduces the issue: source/app.d: http://dpaste.com/2QCSXC1 and public/index.html: http://dpaste.com/02QANJY I would really appreciate if anyone could help me fix this. Thanks!I don't think it is safe to pass a vibe-d Websocket to another thread. It might very well insist on staying on the thread it is created from. Instead you could do all reading in the handler function and then only pass the (immutable) data to another thread.
Mar 22 2019
On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote:On Friday, 22 March 2019 at 20:23:05 UTC, a wrote:Hm, I might have to do that. But would that explain why is works fine for a little while before crashing?Here is some minimal code that reproduces the issue: source/app.d: http://dpaste.com/2QCSXC1 and public/index.html: http://dpaste.com/02QANJY I would really appreciate if anyone could help me fix this. Thanks!I don't think it is safe to pass a vibe-d Websocket to another thread. It might very well insist on staying on the thread it is created from. Instead you could do all reading in the handler function and then only pass the (immutable) data to another thread.
Mar 22 2019
On Friday, 22 March 2019 at 20:59:33 UTC, a wrote:On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote: Hm, I might have to do that. But would that explain why is works fine for a little while before crashing?What I forgot to mention is that you are calling methods on the socket from two threads, and I dont think those methods are thread safe. Which would explain the random crashes.
Mar 22 2019
On Friday, 22 March 2019 at 22:51:11 UTC, Sebastiaan Koppe wrote:On Friday, 22 March 2019 at 20:59:33 UTC, a wrote:I tried getting rid of the function calls in the vibe.d thread, but the crashes keep happening. Any other ideas?On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote: Hm, I might have to do that. But would that explain why is works fine for a little while before crashing?What I forgot to mention is that you are calling methods on the socket from two threads, and I dont think those methods are thread safe. Which would explain the random crashes.
Mar 22 2019
On Friday, 22 March 2019 at 23:44:58 UTC, a wrote:On Friday, 22 March 2019 at 22:51:11 UTC, Sebastiaan Koppe wrote:Not sure about WebSockets, but vibe.d often has the requirement that things are accessed from the same thread that created them. I'd try using fibers instead of threads and seeing how that goes.On Friday, 22 March 2019 at 20:59:33 UTC, a wrote:I tried getting rid of the function calls in the vibe.d thread, but the crashes keep happening. Any other ideas?On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote: Hm, I might have to do that. But would that explain why is works fine for a little while before crashing?What I forgot to mention is that you are calling methods on the socket from two threads, and I dont think those methods are thread safe. Which would explain the random crashes.
Mar 24 2019
On Sunday, 24 March 2019 at 09:56:21 UTC, Benjamin Schaaf wrote:On Friday, 22 March 2019 at 23:44:58 UTC, a wrote:I tried getting rid of the function calls in the vibe.d thread, but the crashes keep happening. Any other ideas?On Friday, 22 March 2019 at 22:51:11 UTC, Sebastiaan Koppe wrote:Not sure about WebSockets, but vibe.d often has the requirement that things are accessed from the same thread that created them. I'd try using fibers instead of threads and seeing how that goes.On Friday, 22 March 2019 at 20:59:33 UTC, a wrote:I tried getting rid of the function calls in the vibe.d thread, but the crashes keep happening. Any other ideas?On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote: Hm, I might have to do that. But would that explain why is works fine for a little while before crashing?What I forgot to mention is that you are calling methods on the socket from two threads, and I dont think those methods are thread safe. Which would explain the random crashes.
Apr 20 2019
On Saturday, 20 April 2019 at 19:24:28 UTC, arakan arkino wrote:I tried getting rid of the function calls in the vibe.d thread, but the crashes keep happening. Any other ideas?Could you post your new code, that will probably narrow it down further.
Apr 20 2019
On Friday, 22 March 2019 at 20:49:52 UTC, Sebastiaan Koppe wrote:On Friday, 22 March 2019 at 20:23:05 UTC, a wrote:Also, sending data _to_ the websocket from the 2nd thread works fine.Here is some minimal code that reproduces the issue: source/app.d: http://dpaste.com/2QCSXC1 and public/index.html: http://dpaste.com/02QANJY I would really appreciate if anyone could help me fix this. Thanks!I don't think it is safe to pass a vibe-d Websocket to another thread. It might very well insist on staying on the thread it is created from. Instead you could do all reading in the handler function and then only pass the (immutable) data to another thread.
Mar 22 2019