Closed martinlierschof closed 6 years ago
After a few debug sessions i found the crash. I cannot explain it though but it probably has something to do with the buffer initialisation in when writing to the socket in the following part of the code.
void
connection::do_write()
{
auto self(shared_from_this());
boost::asio::async_write(_socket, boost::asio::buffer(_response.to_buffer()),
[this, self](boost::system::error_code ec, std::size_t) {
As a temporary fix i did the following (MSVC and Lambdas have a lot of bugs so i do not trust lambdas, but this is probably not related). More its the usage of the buffer which i new before the async and only delete when handle_write has been called. Also i tried to do this with a shared_ptr but the same crash.
void
connection::do_write()
{
std::string* resp = new std::string(_response.to_buffer());
boost::asio::async_write(_socket, boost::asio::buffer(*resp),
boost::bind(&connection::handle_write, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, resp));
}
void
connection::handle_write(const boost::system::error_code& ec, std::size_t bytes_transferred, std::string* resp)
{
delete resp;
}
does someone care to explain?
Hey @martinlierschof, sorry for the late response. I'll take a look at this soon.
Hey @martinlierschof, any chance this issue is still reproducible for you? I failed to reproduce on a few OSes but don't have a windows machine to test with.
Using msvc 14 and win10 i get some random crashes/heap corruptions. boost version is 1.6.0. To get it to work in msvc i had to rewrite url::decode and fix some char[dynamicalloc] things in multiplexer. Those rewrites are probably not causing the issue. If you are interested i can send you the code. i have done quite the same implementation as you did (boost asio example) in another project with keep alive and dropping the connection when currently active caused kind of the same corruptions (i cannot access this code anymore due to i left this company).
the exception appears here:
In addition to that i dont see any implementation for http keep alive. Please correct me if iam wrong.