-
Notifications
You must be signed in to change notification settings - Fork 376
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
Segmentation fault, when the client closes the session while the server is inside the callback #49
Comments
Thanks for highlighting this issue. Would it be possible to supply a working example and appropriate instructions to replicate this defect? |
Here is a sample. Run it as "./main n" which "n" is a number. After running make a rest request by curl -H "Content-Type: application/json" -X POST -d 'hi' http://localhost:1984/resource and then kill this curl execution (before 5 seconds). In my system if "n" is 100000, I get a crash. But smaller numbers are ok (I don't know the exact threshold). #include <memory>
#include <cstdlib>
#include <restbed>
#include <string>
#include <sstream>
#include <unistd.h>
#include <iostream>
using namespace std;
using namespace restbed;
int *num;
void post_method_handler( const shared_ptr< Session > session )
{
const auto request = session->get_request( );
int content_length = 0;
request->get_header( "Content-Length", content_length );
session->fetch( content_length, [ ]( const shared_ptr< Session > session, const Bytes & body )
{
fprintf( stdout, "%.*s\n", ( int ) body.size( ), body.data( ) );
stringstream ss;
for (int i = 0; i < *num; ++i)
ss << "abcdef";
sleep(5);
session->close( OK, ss.str());
} );
}
int main( const int argc, const char** argv)
{
if (argc < 1) {
cout << "Usage main <n>" << endl;
return EXIT_SUCCESS;
}
num = new int(stoi(argv[1]));
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "POST", post_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
} |
I've attempted to replicate this issue on the following environments with varying configurations of sleep (1,5,10,15,30) and loop iteration limits (10, 1000, 10000, 100000, 500000).
As of yet I've failed to reproduce the defect. I can see from your back trace you have SSL enabled and potentially a custom failure handler? Would you be willing to provide the exact code, configuration and environment details you are experiencing this issue in? |
Interesting, I installed restbed on Archlinux from this AUR and compiled the above sample file with g++ main.cpp -o main -lcrypto -lssl -lrestbed -lpthread -std=c++11 The same problem happened on Ubuntu. And here is the backtrace of the above sample (gdb) bt |
Ok, could you attempt to pull and build the latest to see if this change fixes your issue? Restbed Build
Example Build
4.0 Release is scheduled for December so hopefully this will resolve the problem. I'll carry on testing from my end as well; Its just nice to have a second opinion. |
Thanks, I admit that the master branch doesn't have this issue. Please close the issue. |
Great news @omidnikta, thanks for all your help. The linked commit resolves this issue and will be available in the 4.0 release this December. |
I have a server that a callback to a request takes a while. Meanwhile if the client closes the connection, I got a segmentation fault in the server. Here is the full backtrace
The text was updated successfully, but these errors were encountered: