Unlock and close only if the client is connected