Send LOGOUT only when closing connection in logged state (#1487784)