chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.9k stars 1.21k forks source link

select_reactor::run ignores error_code #14

Open Urmeli0815 opened 10 years ago

Urmeli0815 commented 10 years ago

In select_reactor.ipp, line 212, the outparam "ec" (error_code) of the socket_ops::select call is ignored.

If I understand the code correctly this can lead to a busy loop when one of the underlying sockets is damaged/invalid. We experienced high CPU usage in our application by one specific thread, especially when the process was idle for a long time or woke from hibernation. The callstack always lead to the select_reactor-Loop.

Some more information: our application makes a client connection to a partner process via async_connect. This internally opens three socket connections for the "self pipe trick" (to support cancellation of asynchronous connections). When I close one of the two "trick" sockets from outside (e. g. via TCPView) the thread wreaks havoc using up one core.

As far as I understand the "trick" sockets are only needed as long as the real connection is not established. If this is the case it would probably be better to clean them up when the connection is established.

MarcelRaad commented 8 years ago

I often have the same problem, but with errorcode 0. The select call wakes up immediately, 0 bytes are read in interrupter.reset(), and the thread burns one CPU core.

MarcelRaad commented 7 years ago

Fixed by #171 .