Comments (7)
Thanks for highlighting this issue. Would it be possible to supply a working example and appropriate instructions to replicate this defect?
from restbed.
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;
}
from restbed.
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).
- FreeBSD
- Windows 7
- CentOS
- Ubuntu
- Solaris
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?
from restbed.
Interesting, I installed restbed on Archlinux from this AUR
https://aur.archlinux.org/packages/restbed/
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
#0 0x0000000000450e0d in asio::ssl::detail::engine::perform(int (asio::ssl::detail::engine::)(void, unsigned long), void_, unsigned long, std::error_code&, unsigned long_) ()
#1 0x00000000004521ef in asio::ssl::detail::io_op<asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_serviceasio::ip::tcp >, asio::ssl::detail::write_opasio::const_buffers_1, asio::detail::write_op<asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_serviceasio::ip::tcp > >, asio::const_buffers_1, asio::detail::transfer_all_t, std::function<void (std::error_code const&, unsigned long)> > >::operator()(std::error_code, unsigned long, int) ()
#2 0x0000000000452d99 in asio::detail::write_op<asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_serviceasio::ip::tcp > >, asio::const_buffers_1, asio::detail::transfer_all_t, std::function<void (std::error_code const&, unsigned long)> >::operator()(std::error_code const&, unsigned long, int) ()
#3 0x00000000004505db in restbed::detail::SocketImpl::write(std::vector<unsigned char, std::allocator > const&, std::function<void (std::error_code const&, unsigned long)> const&) ()
#4 0x000000000044cc1d in restbed::detail::SessionImpl::transmit(restbed::Response const&, std::function<void (std::error_code const&, unsigned long)> const&) const ()
#5 0x0000000000447cb8 in restbed::Session::close(restbed::Response const&) ()
#6 0x0000000000449b08 in restbed::Session::close(int, std::vector<unsigned char, std::allocator > const&, std::multimap<std::string, std::string, std::lessstd::string, std::allocator<std::pair<std::string const, std::string> > > const&) ()
#7 0x0000000000449c2b in restbed::Session::close(int, std::string const&, std::multimap<std::string, std::string, std::lessstd::string, std::allocator<std::pair<std::string const, std::string> > > const&) ()
#8 0x000000000044b2d8 in restbed::detail::SessionImpl::failure(std::shared_ptrrestbed::Session, int, std::exception const&) const ()
#9 0x0000000000446308 in std::_Function_handler<void (std::error_code const&, unsigned long), restbed::Session::close(restbed::Response const&)::{lambda(std::error_code const&, unsigned long)#1}>::M_invoke(std::Any_data const&, std::error_code const&, unsigned long&&) ()
#10 0x0000000000451324 in asio::detail::write_op<asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_serviceasio::ip::tcp >, asio::const_buffers_1, asio::detail::transfer_all_t, std::function<void (std::error_code const&, unsigned long)> >::operator()(std::error_code const&, unsigned long, int) ()
#11 0x0000000000451516 in asio::detail::reactive_socket_send_op<asio::const_buffers_1, asio::detail::write_op<asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_serviceasio::ip::tcp >, asio::const_buffers_1, asio::detail::transfer_all_t, std::function<void (std::error_code const&, unsigned long)> > >::do_complete(void, asio::detail::scheduler_operation, std::error_code const&, unsigned long) ()
#12 0x000000000041f66b in restbed::Service::start(std::shared_ptr<restbed::Settings const> const&) ()
#13 0x000000000040909b in main ()
from restbed.
Ok, could you attempt to pull and build the latest to see if this change fixes your issue?
Restbed Build
git clone --recursive https://github.com/corvusoft/restbed.git
mkdir restbed/build
cd restbed/build
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES ..
make install
make test
Example Build
g++ -o test test.cpp -lrestbed -lpthread -I restbed/distribution/include -L restbed/distribution/library -std=c++11
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.
from restbed.
Thanks, I admit that the master branch doesn't have this issue. Please close the issue.
from restbed.
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.
from restbed.
Related Issues (20)
- include `pkgconfig` as part of build
- Is there a way to start the server with a non-blocking call and continue working on the same thread? HOT 1
- Why is the CMake config putting "std=gnu++14" in Clang invocations? HOT 4
- http client read timeout results in nothing HOT 1
- The size of the body may cause problems HOT 2
- Suspected memory leak HOT 1
- MINSIGSTKSZ error during building HOT 2
- Cannot buid a static Windows restbed library without export any symbol
- Example/HTTPS_SERVICE error
- Only one handler works in example/RESOURCE_FILTERING. HOT 1
- ask for help:: How to send the main body content multiple times? HOT 1
- CMakeList.txt typos for ssl
- Any idea how I can use restbed in c++ to make PayPal payments using their REST API?
- SSL/TLS: Renegotiation DoS Vulnerability (CVE-2011-1473, CVE-2011-5094)
- Linking with external Asio does not work
- Wrong project version in CMakeLists.txt for tag 4.8
- Permissive LIcense ? HOT 1
- http client post method HOT 1
- Segmentation Fault HOT 1
- Facing issue while building with external libraries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restbed.