Boost C++ Libraries: Ticket #8795: async_connect incorrectly reports success on failure https://svn.boost.org/trac10/ticket/8795 <p> I've found a regression between 1.53 to 1.54; if you compile boost/libs/asio/example/cpp11/chat/chat_client.cpp and point it at a host and port that doesn't exist or refuses the connection, instead of coming back with an error, such as host not found or connection refused, it reports success (on the conversion to bool). (you might want to embellish the example with a std::cout &lt;&lt; error_code.message() &lt;&lt; std::endl;) </p> <p> This appears to be the case across Linux, Darwin, iOS and Android. </p> <p> synchronous connect seems to work correctly (i.e., echo/blocking_tcp_echo_client.cpp) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8795 Trac 1.4.3 stephen.pope@… Tue, 16 Jul 2013 17:59:47 GMT <link>https://svn.boost.org/trac10/ticket/8795#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:1</guid> <description> <p> Upgrading my own code to use 1.54.0 instead of 1.53.0, I also encountered this same problem. It appears to be due to the refactoring of the socket_ops::non_blocking_connect() function, which now calls socket_ops::connect() and then (unless getting back boost::asio::error::already_started), calls socket_ops::getsockopt with SO_ERROR. The problem is that the call to ::connect() within socket_ops::connect() has already effectively cleared the error (and set errno appropriately), and ec already contains the desired error code, so the call to getsockopt ends up clearing the error information from ec, making it appear to have succeeded. </p> <p> Unfortunately I am not familiar enough with the intent of the changes to propose the correct solution, although I suspect it would be to only call socket_ops::getsockopt() if the call to socket_ops::connect() did not itself return an error. </p> </description> <category>Ticket</category> </item> <item> <author>naidu.trk@…</author> <pubDate>Wed, 17 Jul 2013 12:11:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:2</guid> <description> <p> I encountered this while working with websocketpp library which uses boost asio. connect returns success despite the failure to connect. websocketpp returns the same success to the application. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 18 Jul 2013 07:03:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:3</guid> <description> <p> I also have same problem with boost 1.54.0. The error code from async_connect()'s callback is always success in spite of connection failed. </p> </description> <category>Ticket</category> </item> <item> <author>junk@…</author> <pubDate>Tue, 30 Jul 2013 20:25:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:4</guid> <description> <p> I have the same problem. I created a workaround in my code by calling connect and then posting the response to the async_connect handle. This, of course, blocks the calling thread :(. </p> </description> <category>Ticket</category> </item> <item> <author>Ramon Casellas <ramon.casellas@…></author> <pubDate>Fri, 02 Aug 2013 09:42:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:5</guid> <description> <p> Confirmed also in boost trunk as of 20130801 (1.55) linux ubuntu saucy 64 bits. A regression that is causing services that are supposed to reconnect on failure to proceed. </p> <p> Quite easy to reproduce using the async_client in the examples without any listening http server. Add a debug trace (should get connection refused): </p> <pre class="wiki">root@pookie:/tmp# g++ -c -o client.o client.cpp root@pookie:/tmp# g++ -o client client.o -lboost_system -lboost_thread -lpthread root@pookie:/tmp# ./client localhost /index.html handle_connect Error: system:0 Error: Broken pipe </pre><p> Thanks R. </p> </description> <category>Ticket</category> </item> <item> <author>jft@…</author> <pubDate>Wed, 14 Aug 2013 20:02:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:6</guid> <description> <p> You cannot even use boost::asio::ip::tcp::iostream because the connect method makes use of async_connect. I would consider this a huge bug and I am surprised there are only a few responses to this ticket. I spend a considerable amount of time debugging my projects today to find this bug (I use Arch Linux and they updated recently). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 15 Aug 2013 20:38:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:7</guid> <description> <p> For my own use, I found that simply inserting: </p> <p> if (ec) return true; </p> <p> at line 524 of boost/asio/detail/impl/socket_ops.ipp (i.e. in non_blocking_connect() after the check for error::already_started and before calling getsockopt()) has proven to be a reasonable workaround. Again, as I do not understand the intent of the changes from 1.53.0, I am not sure that this is the correct bugfix, so YMMV. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mvd</dc:creator> <pubDate>Fri, 16 Aug 2013 09:22:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:8</guid> <description> <p> I confirm the bug in BOOST 1.54. The connect handler reports success although the connect attempt failed. </p> </description> <category>Ticket</category> </item> <item> <author>david.keegan@…</author> <pubDate>Fri, 23 Aug 2013 15:37:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:9</guid> <description> <p> Yes, I've hit this problem too on Linux. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 26 Aug 2013 15:17:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:10</guid> <description> <p> I confirm the problem in 1.54.0 boost. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 27 Aug 2013 23:05:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:11</guid> <description> <p> On CentOS 6.4 (64bit), upgrade from 1.49.0 to 1.54.0 introduced this issue for me. The error code in connect handler reports success and the socket appears to be is_open(). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 28 Aug 2013 12:50:46 GMT</pubDate> <title>summary changed https://svn.boost.org/trac10/ticket/8795#comment:12 https://svn.boost.org/trac10/ticket/8795#comment:12 <ul> <li><strong>summary</strong> <span class="trac-field-old">async_connect oncorrectly reports success on failure</span> → <span class="trac-field-new">async_connect incorrectly reports success on failure</span> </li> </ul> Ticket Antonio Di Monaco <tony@…> Sat, 31 Aug 2013 15:29:34 GMT <link>https://svn.boost.org/trac10/ticket/8795#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:13</guid> <description> <p> Confirmed on Slackware64, using boost 1.54.0 </p> </description> <category>Ticket</category> </item> <item> <author>agazso@…</author> <pubDate>Tue, 10 Sep 2013 13:33:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:14</guid> <description> <p> For me this fix worked </p> <p> if (ec == asio::error::connection_refused) return true; </p> <p> at line 524 of boost/asio/detail/impl/socket_ops.ipp </p> <p> It seems that when <code>connect</code> returns <code>ECONNREFUSED</code> then <code>getsockopt</code> returns no error. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Tue, 01 Oct 2013 10:44:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8795#comment:15 https://svn.boost.org/trac10/ticket/8795#comment:15 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Minimal fix on trunk in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85738" title="Fix a regression where, on some platforms, errors from async_connect ...">[85738]</a>. Subsequent cleanup in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85739" title="Remove unused parameters and member variables.">[85739]</a>. Merged to release in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85838" title="Merge asio from trunk. ...">[85838]</a>. </p> Ticket anonymous Tue, 18 Nov 2014 16:55:08 GMT <link>https://svn.boost.org/trac10/ticket/8795#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:16</guid> <description> <p> With Boost 1.55 running on Windows 8.1 I was seeing a single false connection. On Boost 1.56 I see repeated false connections, over and over again. </p> <p> By "false connections" I mean that the connect handler for async_connect gets called right away (when the other end of the socket is not there), with error_code zero and where conn-&gt;socket.is_open() return true. Stepping into the boost code I see in win_iocp_io_service.ipp line 405 result_ec is 10057 (WSAENOTCONN). The next line of code (ec = boost::system::error_code();) sets ec to zero. </p> <p> Does anyone else see this? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 13 Apr 2016 21:22:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:17</guid> <description> <p> I am experiencing this bug using MSVC 14 and Boost 1.60. </p> <p> No asynchronous solution in sight. Finnicky. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 13 Apr 2016 22:06:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:18</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/8795#comment:17" title="Comment 17">anonymous</a>: </p> <blockquote class="citation"> <p> I am experiencing this bug using MSVC 14 and Boost 1.60. </p> <p> No asynchronous solution in sight. Finnicky. </p> </blockquote> <p> UPDATE: Replacing asio::ip::tcp::acceptor.cancel() with asio::ip::tcp::acceptor.close() in another thread, fixes some oddity within a shared asio::io_service... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 05 Apr 2017 10:01:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8795#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:19</guid> <description> <p> Boost 1.63.0, Windows 10 64-bit. </p> <p> Also shows no error despite the connection failed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 06 Apr 2017 06:11:17 GMT</pubDate> <title>status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/8795#comment:20 https://svn.boost.org/trac10/ticket/8795#comment:20 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.54.0</span> → <span class="trac-field-new">Boost 1.63.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket anonymous Thu, 06 Apr 2017 06:11:19 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/8795#comment:20 https://svn.boost.org/trac10/ticket/8795#comment:20 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket anonymous Fri, 04 Aug 2017 08:25:12 GMT <link>https://svn.boost.org/trac10/ticket/8795#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8795#comment:21</guid> <description> <p> Boost 1.59 Win64 has the same issue! </p> </description> <category>Ticket</category> </item> </channel> </rss>