[#2931] Only cancel SelectionKey if connection is not pending

Motivation:

We must only cancel the SelectionKey if the connection is not pending while try to workaround the epoll bug, otherwise we may fail to notify the future later.

Modifications:

Check if the connection is pending before cancel the SelectionKey.

Result:

Only cancel correct SelectionKeys and so also make sure the futures are notified.