0

below is a small snippet that is throwing an access violation when running. I am using Visual Studio 2015 and boost 1.60.0 and when calling

m_socket.async_connect(end_point, yieldw[ec]);

an access violation is occurring in a boost file "socket_ops.ipp" at the line

"socket_type s = error_wrapper(::WSASocketW(af, type, protocol, 0, 0,WSA_FLAG_OVERLAPPED),ec);"

The exception is "Unhandled exception at 0x000007FEFD598A2F (KernelBase.dll) in ConsoleApplication4.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

#include "stdafx.h"
#include <memory>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/write.hpp>
#include <cassert>
#include <thread>
#include <chrono>

int main()
{

boost::asio::io_service m_io_service;
//boost::asio::io_service::strand m_socket_strand{ m_io_service };
boost::asio::io_service::work m_work(m_io_service);
boost::asio::ip::tcp::socket m_socket(m_io_service);

std::thread thread([&]() { 
    m_io_service.run(); 
});

boost::asio::ip::tcp protocol_family{ boost::asio::ip::tcp::v4() };
boost::asio::ip::tcp::resolver::query query(protocol_family, "localhost", std::to_string(2101));

boost::asio::ip::tcp::resolver resolver(m_io_service);

boost::asio::ip::tcp::resolver::iterator iterator{ resolver.resolve(query) }; // Hosts can have multiple addresses.
/*boost::asio::ip::tcp::resolver::iterator end_iterator{ iterator };
end_iterator++;
boost::asio::ip::tcp::resolver::iterator end;

if (end_iterator != end)
{
    std::ostringstream endpoint_descripiton;
}*/

assert(iterator != boost::asio::ip::tcp::resolver::iterator());

auto end_point = iterator->endpoint();

boost::asio::spawn(m_io_service, [&, end_point](boost::asio::yield_context yieldw)
{
    boost::system::error_code ec;

    m_socket.async_connect(end_point, yieldw[ec]);

    if (ec != boost::system::errc::success)
    {
        std::this_thread::sleep_for(std::chrono::seconds(5));
    }
    else
    {
    }

});


std::this_thread::sleep_for(std::chrono::seconds(20));
return 0;

}

Machavity
  • 30,841
  • 27
  • 92
  • 100

1 Answers1

0

Ok after digging around I found out this issue only occurred for me in x64 debug, all other configurations where fine. So I figured that maybe something else is wrong with my setup or libraries. After trying the latest boost 1_63_0 and discovering the error went away, I back tracked through versions until the error appeared again and then went to check the release notes of the last working copy. I found the following https://svn.boost.org/trac/boost/ticket/12215 which has the same issues I was having. Using boost 1_62_0 or later fixes the issue.