Opened 8 years ago

Last modified 6 years ago

#10447 new Bugs

io_service destructor hangs if serial_port read is queued, even if not running

Reported by: Martinho Fernandes <martinho.fernandes@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

The following program does not terminate.

#include <boost/asio.hpp>

int main() {
    auto* ios = new boost::asio::io_service;
    auto* port = new boost::asio::serial_port(*ios);
    port->open("COM6");
    char c;
    boost::asio::async_read(*port, boost::asio::buffer(&c, 1), [](boost::system::error_code, int) {});

    delete ios;
}

Despite the fact that the io_service is not running, its destructor hangs if there is a pending async_read from a serial_port. If that read completes (by receiving one byte), the program terminates.

Change History (3)

comment:1 by Martinho Fernandes <martinho.fernandes@…>, 8 years ago

Oh, I can only reproduce this on Windows.

comment:2 by viboes, 8 years ago

Component: Noneasio
Owner: set to chris_kohlhoff

comment:3 by anonymous, 6 years ago

User error: objects dependent on an io_service should be destroyed prior to that io_service's destruction.

Note: See TracTickets for help on using tickets.