-
-
Notifications
You must be signed in to change notification settings - Fork 2k
multithreaded sessions engineering #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you help me understand exactly what the questions is? What I think is happening based on your description: Each connection performs some sort of authentication/login step that results in it being associated with a Session. A Session can have multiple connections. Requests are processed and sent to all connections in the associated Session? The issue happens when a connection is closed by the remote endpoint after a request is received but before the result is written out to the socket. Is the issue that connections correctly close and you are unsure how to clean up or avoid sending to closed connections? Or are connections closing before you think they should be? I.e you would expect request -> response -> close but get request -> close -> response due to thread scheduling? Is this an intermittent problem or is it consistently reproducible? |
hello zaphoyd, thanks for taking the time to reply to my question. You have correctly assessed the problem although I am only sending data to those connections that have sent a request to be answered. I believe your implementation is working great but I am unsure how to avoid sending to closed connections. The connection is closed by the remote endpoint (pressing f5 in a browser that connects to the server via javascript) after a request is received but before the result is written out to the socket. This causes a segmentation fault when trying to use the connection_ptr. |
Okay. You've hit on a point where the 0.2.x version of this library has some known issues. The library wasn't designed to be thread safe and the retrofitting that I have attempted to do has some problems, as you have noticed. That said, there should be a guard even in 0.2.x that should silently ignore sends to connections that are closing or closed. If you still have a connection_ptr, that should be a reference counted shared pointer that keeps the dead connection around even after the library has forgotten about it. This should mean that it is always safe to call the send method of a connection_ptr from anywhere. Can you give me a little more information about the segfault you are getting? In particular, what thread is send being called from and how did that thread get its copy of the connection_ptr. Is it being called from inside a library handler or was it passed out to another worker thread? Also: If you are doing serious multithreaded work, you should look for the 0.3 preview release later this month. It has been reworked to provide much more robust thread safety. |
Some detail to how send is being called: the segfault appears when I try to copy the local copy of the connection_ptr in the current Request to the Request that is being used to build the reply. In short, its a worker thread that got a copy of the connection_ptr through the on_message handler. here's my gdb trace from windows 7 64bit compiling everything for 32bit and running it in the 64bit environment. 0x3f) 0x3b) If I call get_state on the connection instead of copying it over, I get the following backtrace: Program received signal SIGSEGV, Segmentation fault. If I just call connection_ptr->send instead of trying to construct a Request and put it on the queue, I get this backtrace: Program received signal SIGSEGV, Segmentation fault. 0x1f3) I got this websocket version from this github site on October 12 as a zip file. Boost is 1.51. Everything is compiled using -std=c++0x -m32 with mingw and gcc 4.7.2 win32 from: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-win32/sjlj/ Edit: I just cloned the master branch of websocketpp and tried it again but the same errors occur. |
Closing this as 0.2.x has known multithreading issues that won't be fixed. Solution is to use 0.3.x if multithreading is important. |
Not sure if this is the right place to ask this:
I'm using the multi-threaded server example with the producer/consumer model for thread management and have built on that.
I created a Session class that has multiple connections associated with it based on login data but am having problems when the on_close handler is called and Requests are still being processed which use the connection which is closed.
I'm looking for a way to solve this and was wondering if you could give me either a recommendation for literature or perhaps way to solve this problem.
The text was updated successfully, but these errors were encountered: