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

enhance documentation that session on error handler could point to null #515

Open
maggu2810 opened this issue Apr 1, 2022 · 1 comment

Comments

@maggu2810
Copy link

maggu2810 commented Apr 1, 2022

We are using the tag 4.8 of the restbed source code.

We are using the following "simple" error handler:

    restbed::Service service;

    service.set_error_handler([](const int                                tbd,
                                 const std::exception&                    exc,
                                 const std::shared_ptr<restbed::Session>& session) {
        if (session->is_open())
        {
            session->close(restbed::INTERNAL_SERVER_ERROR);
        }
        const std::type_info& typeInfo = typeid(exc);
        std::cerr << "ERROR HANDLER: tbd=" << tbd << ", exc.what: " << exc.what()
                  << ", exc type info name: " << typeInfo.name() << std::endl;
    });

I can reproduce errors by reload the pages while the loading is in progress (so the cause seems to be breaking the client connection while data is transmitted).

The call to session->is_open() seems to be "dangerous". As sometimes it crashes by SIGSEGV

Here a stack trace:

x76d349d4 in restbed::Session::is_open() const () from /usr/lib/librestbed.so.4
(gdb) bt  
#0  0x76d349d4 in restbed::Session::is_open() const () from /usr/lib/librestbed.so.4
#1  0x54ab8702 in <lambda(int, const std::exception&, const std::shared_ptr<restbed::Session>&)>::operator() (
    session=..., exc=..., tbd=408, __closure=<optimized out>)
    at /opt/yocto/sysroots/armv7at2hf-neon-poky-linux-gnueabi/usr/include/c++/9.3.0/bits/shared_ptr_base.h:1309
#2  std::_Function_handler<void(int, const std::exception&, std::shared_ptr<restbed::Session>), https(const AppSrvConfig&, const std::shared_ptr<IpcHandlerInterface>&)::<lambda(int, const std::exception&, const std::shared_ptr<restbed::Session>&)> >::_M_invoke(const std::_Any_data &, int &&, const std::exception &, std::shared_ptr<restbed::Session> &&) (__functor=..., __args#0=<optimized out>, __args#1=..., __args#2=...)
    at /opt/yocto/sysroots/armv7at2hf-neon-poky-linux-gnueabi/usr/include/c++/9.3.0/bits/std_function.h:300
#3  0x76d1b99e in restbed::detail::SocketImpl::connection_timeout_handler(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&) () from /usr/lib/librestbed.so.4
#4  0x76d1f61e in void std::__invoke_impl<void, void (restbed::detail::SocketImpl::*&)(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&), restbed::detail::SocketImpl*&, std::shared_ptr<restbed::detail::SocketImpl>&, std::error_code const&>(std::__invoke_memfun_deref, void (restbed::detail::SocketImpl::*&)(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&), restbed::detail::SocketImpl*&, std::shared_ptr<restbed::detail::SocketImpl>&, std::error_code const&) () from /usr/lib/librestbed.so.4
#5  0x76d1f9f4 in void asio::detail::strand_service::dispatch<asio::detail::binder1<std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, std::error_code> >(asio::detail::strand_service::strand_impl*&, asio::detail::binder1<std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, std::error_code>&) () from /usr/lib/librestbed.so.4
#6  0x76d202e4 in asio::detail::completion_handler<asio::detail::rewrapped_handler<asio::detail::binder1<asio::detail::wrapped_handler<asio::io_context::strand, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, asio::detail::is_continuation_if_running>, std::error_code>, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)> >, asio::io_context::basic_executor_type<std::allocator<void>, 0u> >::do_complete(void*, asio::detail::scheduler_operation*, std::error_code const&, unsigned int) () from /usr/lib/librestbed.so.4
#7  0x76d1d4c0 in ?? () from /usr/lib/librestbed.so.4
#8  0x76d1fbda in void asio::detail::strand_service::dispatch<asio::detail::rewrapped_handler<asio::detail::binder1<asio::detail::wrapped_handler<asio::io_context::strand, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, asio::detail::is_continuation_if_running>, std::error_code>, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)> > >(asio::detail::strand_service::strand_impl*&, asio::detail::rewrapped_handler<asio::detail::binder1<asio::detail::wrapped_handler<asio::io_context::strand, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, asio::detail::is_continuation_if_running>, std::error_code>, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)> >&) () from /usr/lib/librestbed.so.4
#9  0x76d1fdfc in asio::detail::wait_handler<asio::detail::wrapped_handler<asio::io_context::strand, std::_Bind<void (restbed::detail::SocketImpl::*(restbed::detail::SocketImpl*, std::shared_ptr<restbed::detail::SocketImpl>, std::_Placeholder<1>))(std::shared_ptr<restbed::detail::SocketImpl>, std::error_code const&)>, asio::detail::is_continuation_if_running>, asio::any_io_executor>::do_complete(void*, asio::detail::scheduler_operation*, std::error_code const&, unsigned int) () from /usr/lib/librestbed.so.4
#10 0x76ce492e in ?? () from /usr/lib/librestbed.so.4
#11 0x76d31c78 in restbed::Service::start(std::shared_ptr<restbed::Settings const> const&) ()
   from /usr/lib/librestbed.so.4
#12 0x54ac81b8 in https (config=..., ipcHandler=...)
    at /opt/yocto/sysroots/armv7at2hf-neon-poky-linux-gnueabi/usr/include/c++/9.3.0/ext/atomicity.h:96
#13 0x54ab77d0 in std::__invoke_impl<void, void (*)(AppSrvConfig const&, std::shared_ptr<IpcHandlerInterface> const&), AppSrvConfig, std::shared_ptr<IpcHandlerInterface> > (__f=<optimized out>)
@maggu2810
Copy link
Author

Got it: session.get() == nullptr

Perhaps you could enhance at least the documentation that the shared_ptr could be / point to a nullptr?

@maggu2810 maggu2810 changed the title crash sometimes on is_open call in exception handler enhance documentation that session on error handler could point to null Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant