Skip to content
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

Resolve multithread crash (#175) #225

Open
wants to merge 4 commits into
base: master
from
Open

Conversation

@qchateau
Copy link

qchateau commented Dec 11, 2018

Hi, the main goal of this PR is to solve issue #175. Here is the description of what each commit does:

a0e6123 : Add a unit test reproducting issue #175
b18569a : fix thread safety in session management
8a98779 : Prevent the server_session to be destroyed while its closing code is still queued, causing a segfault
b134678 : Fixed socket double close. If (exit_) is true, then the session is already closed and the socket_.close() is queued

We use your library actively, please give me a feedback on this PR so it could be accepted in the official repository. It would be beneficial for everyone to avoid another fork.

@qchateau qchateau force-pushed the qchateau:multithread branch from afa298a to b134678 Dec 11, 2018
@codecov
Copy link

codecov bot commented Dec 11, 2018

Codecov Report

Merging #225 into master will increase coverage by 3.87%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #225      +/-   ##
==========================================
+ Coverage   93.69%   97.57%   +3.87%     
==========================================
  Files          37       37              
  Lines         984     1113     +129     
  Branches       59        0      -59     
==========================================
+ Hits          922     1086     +164     
+ Misses         29       27       -2     
+ Partials       33        0      -33
Impacted Files Coverage Δ
lib/rpc/detail/server_session.cc 100% <100%> (+19.29%) ⬆️
tests/rpc/server_session_test.cc 100% <100%> (ø) ⬆️
lib/rpc/server.cc 98.64% <100%> (+4.1%) ⬆️
lib/rpc/this_handler.cc 100% <0%> (ø) ⬆️
tests/testmain.cc 100% <0%> (ø) ⬆️
lib/rpc/this_server.cc 100% <0%> (ø) ⬆️
lib/rpc/this_session.cc 100% <0%> (ø) ⬆️
tests/rpc/this_session_test.cc 100% <0%> (ø) ⬆️
include/rpc/this_handler.inl 100% <0%> (ø) ⬆️
include/rpc/dispatcher.inl 100% <0%> (ø) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b00c4c...613c70b. Read the comment docs.

@qchateau qchateau force-pushed the qchateau:multithread branch from b134678 to 613c70b Dec 11, 2018
@qchateau qchateau closed this Dec 16, 2018
@qchateau qchateau deleted the qchateau:multithread branch Dec 16, 2018
@qchateau qchateau restored the qchateau:multithread branch Dec 16, 2018
@qchateau qchateau reopened this Dec 16, 2018
@sztomi
Copy link
Collaborator

sztomi commented Dec 17, 2018

And for this one as well, I'll review them at the same time (this week some time).

@dossjh
Copy link

dossjh commented Jul 4, 2019

@qchateau I am using your fork, however muiltthread servers still crash for me. As soon as the client closes the connection regardless if the client is doing async or not. Do you have any ideas?

@qchateau
Copy link
Author

qchateau commented Jul 5, 2019

I don't have much time atm but send me a sample code to reproduce your crash and I'll take a look

@dossjh
Copy link

dossjh commented Jul 11, 2019

@qchateau

I don't have much time atm but send me a sample code to reproduce your crash and I'll take a look

Ok, I have figured out what the cause is, and created a MWE.

in the calculator example if you replace the subtraction function with:
struct subtractor { double operator()(double a, double b) { int ax = 0; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::cout << "Sleep complete"; return a - b; } };

Then you change the server to run async(4) (for example, any thing more than 1 will cause the crash). Then close the client before the function returns.

The server will crash immediately. I consider myself a beginner, but I really love this RPC implementation, it is the simplest I have seen, so I will see if I can figure something out!

@dossjh
Copy link

dossjh commented Jul 15, 2019

@qchateau I know you said you dont have much time so i made a gist with the proper code. The example client doesn't need to be modified.

server: https://gist.github.com/dossjh/582b050802a9634df756b0e9c0969baa

Thanks for your help.

@qchateau
Copy link
Author

qchateau commented Jul 15, 2019

I don't know how you get there. Testing it on my fork and it runs without troubles. I replaced calculator_server.cc with your codeand had to change the server port to rpc::constants::DEFAULT_PORT.

$ git show
commit c4fb37acbe67ec99e47e5187acd2a7450bde0cec (HEAD -> master, origin/master, origin/HEAD)
Merge: 9fabdbf 38315c0
Author: Quentin Chateau <quentin.chateau@gmail.com>
Date:   Thu Jun 20 23:54:30 2019 +0200

    Merge pull request #15 from tan-yue/master
    
    patch for gcc version < 5 std::put_time unavailable

I'm using Ubuntu 18.10, GCC 8.3.0, and compiled in Release mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.