id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 8995,"async_connect reports ""success"" even if the connection is refused",info@…,chris_kohlhoff,"While the synchronous (blocking) connect correctly reports ""Connection refused"", the asynchronous call always results in ""Success"". The code below is a simple test case where I would expect that both ways result in ""Connection refused"" because there is no service running on the port 1234. Because the async_connect ""is successful"" a following write attempt fails with ""broken pipe"" (of course, there is no service running at this port). The problem gets worse if you replace ""127.0.0.1"" with ""localhost"" and you have a service running at 1234 using IPv4 but your system also supports IPv6. I would expect that the attempt on IPv6 fails but a second attempt on IPv4 succeeds. On my system ""localhost"" resolves first to IPv6 and the async_connect reports a successful connect which then fails with ""broken pipe"" on attempting to write to the socket. The connection using IPv4 is not established this way. Using the blocking call to ""connect"", everything works as expected. {{{#!cpp #include #include using namespace boost; int main() { asio::io_service io_service; asio::ip::tcp::resolver resolver(io_service); asio::ip::tcp::socket socket(io_service); system::error_code error; asio::ip::tcp::resolver::iterator endpoint_iterator; endpoint_iterator = resolver.resolve(asio::ip::tcp::resolver::query(""127.0.0.1"", ""1234"")); connect(socket, endpoint_iterator, error); std::cout << ""synchronous connect status: "" << error.message() << std::endl; error = asio::error::eof; resolver.async_resolve( asio::ip::tcp::resolver::query(""127.0.0.1"", ""1234""), [&] (const system::error_code &ec, asio::ip::tcp::resolver::iterator endpoint) { error = ec; endpoint_iterator = endpoint; if (!ec) { async_connect( socket, endpoint_iterator, [&] (const system::error_code &ec, asio::ip::tcp::resolver::iterator it) { std::cout << ""asynchronous connect status: "" << ec.message() << std::endl; } ); } } ); io_service.run(); return 0; } }}}",Bugs,closed,To Be Determined,asio,Boost 1.54.0,Problem,duplicate,,