If key is not valid, close connection