[#2104] Make sure we only act on the SelectionKey if it is valid