IOManager connect and accept failure handling. Fixes #3035

 * Cherry-picked from release-2.1.
 * Small changes: channel.socket -> sock