jgaa / restc-cpp

Modern C++ REST Client library
MIT License
615 stars 95 forks source link

access violation in ConnectionPoolImpl::OnCacheCleanup #15

Closed kwikrick closed 7 years ago

kwikrick commented 7 years ago

Hi Jarle,

I'm getting access violations in ConnectionPoolImpl::OnCacheCleanup. These occur seemingly randomly (i.e. at random points while repeatedly running tests). See track trace below.

I'm running a Windows build, latest commit from 2017-05-19 (SHA 5e7ed3e6c35453fbb2598cf969723b63e28a961d).

It seems that the ConnectionPoolImpl instance has been deleted, but the OnCacheCleanup callback is still invoked by the timer. My app makes repeated calls using RestClient::Create()->ProcessWithPromiseT<>(...), so creating a new client and connection pool for each call repeatedly (right?).

Aside from that, I love the restc-cpp lib. Thank you for creating this!

Rick

Stack trace:

TestVisiLoginRestCpp.exe!restc_cpp::ConnectionPoolImpl::OnCacheCleanup(const boost::system::error_code & error) Line 176 C++ [External Code] TestVisiLoginRestCpp.exe!boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &>,boost::system::error_code>::operator()() Line 48 C++ TestVisiLoginRestCpp.exe!boost::asio::asio_handler_invoke<boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &>,boost::system::error_code> >(boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &>,boost::system::error_code> & function, ...) Line 70 C++ TestVisiLoginRestCpp.exe!boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &>,boost::system::error_code>,std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &> >(boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &>,boost::system::error_code> & function, std::_Binder<std::_Unforced,void (thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &> & context) Line 37 C++ TestVisiLoginRestCpp.exe!boost::asio::detail::wait_handler<std::_Binder<std::_Unforced,void (__thiscall restc_cpp::ConnectionPoolImpl::)(boost::system::error_code const &),restc_cpp::ConnectionPoolImpl const,std::_Ph<1> const &> >::do_complete(boost::asio::detail::win_iocp_io_service owner, boost::asio::detail::win_iocp_operation base, const boost::system::error_code & formal, unsigned int formal) Line 70 C++ TestVisiLoginRestCpp.exe!boost::asio::detail::win_iocp_operation::complete(boost::asio::detail::win_iocp_io_service & owner, const boost::system::error_code & ec, unsigned int bytes_transferred) Line 46 C++ TestVisiLoginRestCpp.exe!boost::asio::detail::win_iocp_io_service::do_one(bool block, boost::system::error_code & ec) Line 406 C++ TestVisiLoginRestCpp.exe!boost::asio::detail::win_iocp_io_service::run(boost::system::error_code & ec) Line 164 C++ TestVisiLoginRestCpp.exe!boost::asio::io_service::run() Line 59 C++ TestVisiLoginRestCpp.exe!restc_cpp::RestClientImpl::Init::__l2::() Line 146 C++ [External Code] [Frames below may be incorrect and/or missing, no symbols loaded for ucrtbased.dll]

jgaa commented 7 years ago

You will get better performance by creating one client, and then calling it repeatedly from the main thread, until you are done (or one client per core you want to use, and then distribute the work among the clients). But this definitely looks like a bug that needs to be fixed.

I'll try to reproduce it.

Thanks for reporting the problem.