boost :: asio + std :: future - Violação de acesso após fechar o soquete

Estou escrevendo um cliente tcp simples para enviar e receber linhas de texto únicas. As operações assíncronas são tratadas pelo std :: future para facilitar o bloqueio de consultas com tempos limite. Infelizmente, meu aplicativo de teste trava com uma violação de acesso ao destruir o objeto do servidor. Aqui está o meu código:

TCPClient.hpp

#ifndef __TCPCLIENT_H__
#define __TCPCLIENT_H__

#include <boost/asio.hpp>
#include <boost/asio/use_future.hpp>
#include <memory>
#include <vector>
#include <future>
#include <thread>
#include <chrono>
#include <iostream>
#include <iterator>

using namespace boost::asio;

class TCPClient {
public:
    TCPClient();
    ~TCPClient();

    void connect(const std::string& address, const std::string& port);
    void disconnect();

    std::string sendMessage(const std::string& msg);
private:
    boost::asio::io_service ioservice;
    boost::asio::io_service::work work;
    std::thread t;

    std::unique_ptr<boost::asio::ip::tcp::socket> socket;
};

inline TCPClient::TCPClient() : ioservice(), work(ioservice) {
    t = std::thread([&]() {
        try {
            ioservice.run();
        }
        catch (const boost::system::system_error& e) {
            std::cerr << e.what() << std::endl;
        }
    });
}

inline TCPClient::~TCPClient() {
    disconnect();
    ioservice.stop();
    if (t.joinable()) t.join();
}

inline void TCPClient::connect(const std::string& address, const std::string& port) {
    socket.reset(new ip::tcp::socket(ioservice));

    ip::tcp::resolver::query query(address, port);
    std::future<ip::tcp::resolver::iterator> conn_result = async_connect(*socket, ip::tcp::resolver(ioservice).resolve(query), use_future);

    if (conn_result.wait_for(std::chrono::seconds(6)) != std::future_status::timeout) {
        conn_result.get(); // throws boost::system::system_error if the operation fails
    }
    else {
        //socket->close();
        // throw timeout_error("Timeout");
        throw std::exception("timeout");
    }
}

inline void TCPClient::disconnect() {
    if (socket) {
        try {
            socket->shutdown(ip::tcp::socket::shutdown_both);
            std::cout << "socket points to " << std::addressof(*socket) << std::endl;
            socket->close();
        }
        catch (const boost::system::system_error& e) {
            // ignore
            std::cerr << "ignored error " << e.what() << std::endl;
        }
    }
}

inline std::string TCPClient::sendMessage(const std::string& msg) {
    auto time_over = std::chrono::system_clock::now() + std::chrono::seconds(4);

    /*
    // Doesn't affect the error
    std::future<size_t> write_fut = boost::asio::async_write(*socket, boost::asio::buffer(msg), boost::asio::use_future);

    try {
        write_fut.get();
    }
    catch (const boost::system::system_error& e) {
        std::cerr << e.what() << std::endl;
    }
    */
    boost::asio::streambuf response;

    std::future<std::size_t> read_fut = boost::asio::async_read_until(*socket, response, '\n', boost::asio::use_future);
    if (read_fut.wait_until(time_over) != std::future_status::timeout) {
        std::cout << "read " << read_fut.get() << " bytes" << std::endl;
        return std::string(std::istreambuf_iterator<char>(&response), std::istreambuf_iterator<char>());
    }
    else {
        std::cout << "socket points to " << std::addressof(*socket) << std::endl;
        throw std::exception("timeout");
    }
}
#endif

main.cpp

#include <iostream>

#include "TCPClient.hpp"

int main(int argc, char* argv[]) {
    TCPClient client;
    try {
        client.connect("localhost", "27015");
        std::cout << "Response: " << client.sendMessage("Hello!") << std::endl;
    }
    catch (const boost::system::system_error& e) {
        std::cerr << e.what() << std::endl;
    }
    catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
    }
    system("pause");
    return 0;
}

A saída é "timeout" conforme o esperado (o servidor de teste não envia dados de propósito), masioservice.run() trava imediatamente (violação de acesso) após fechar o soqueteTCPClient::disconnect(). Estou fazendo alguma má gestão de memória aqui?

O compilador é o MSVC 12.0.31101.00, atualização 4 (Visual Studio 2013)

questionAnswers(2)

yourAnswerToTheQuestion