Close a session

@param loginInput login information
@throws SnowflakeSQLException if failed to close session
@throws SFException           if failed to close session
962846
static public void closeSession(LoginInput loginInput)
  throws SFException, SnowflakeSQLException
  {
    logger.debug(" public void close() throws SFException");

    // assert the following inputs are valid
    AssertUtil.assertTrue(loginInput.getServerUrl() != null,
                          "missing server URL for closing session");

    AssertUtil.assertTrue(loginInput.getSessionToken() != null,
                          "missing session token for closing session");

    AssertUtil.assertTrue(loginInput.getLoginTimeout() >= 0,
                          "missing login timeout for closing session");

    HttpPost postRequest = null;

    try
    {
      URIBuilder uriBuilder;

      uriBuilder = new URIBuilder(loginInput.getServerUrl());

      uriBuilder.addParameter(SF_QUERY_SESSION_DELETE, "true");
      uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID,
                              UUID.randomUUID().toString());

      uriBuilder.setPath(SF_PATH_SESSION);

      postRequest = new HttpPost(uriBuilder.build());

      postRequest.setHeader(SF_HEADER_AUTHORIZATION,
                            SF_HEADER_SNOWFLAKE_AUTHTYPE + " "
                            + SF_HEADER_TOKEN_TAG + "=\""
                            + loginInput.getSessionToken() + "\"");

      setServiceNameHeader(loginInput, postRequest);

      String theString = HttpUtil.executeRequest(postRequest,
                                                 loginInput.getLoginTimeout(),
                                                 0, null);

      JsonNode rootNode;

      logger.debug(
          "connection close response: {}",
          theString);

      rootNode = mapper.readTree(theString);

      SnowflakeUtil.checkErrorAndThrowException(rootNode);
    }
    catch (URISyntaxException ex)
    {
      throw new RuntimeException("unexpected URI syntax exception", ex);
    }
    catch (IOException ex)
    {
      logger.error("unexpected IO exception for: " + postRequest,
                   ex);
    }
    catch (SnowflakeSQLException ex)
    {
      // ignore session expiration exception
      if (ex.getErrorCode() != Constants.SESSION_EXPIRED_GS_CODE)
      {
        throw ex;
      }
    }
  }
1342126
def close_database_session(session):
    """"""

    try:
        session.close()
    except OperationalError as e:
        raise DatabaseError(error=e.orig.args[1], code=e.orig.args[0])
1353023
public void endParsing() throws SnowflakeSQLException
  {
    if (partialEscapedUnicode.position() > 0)
    {
      partialEscapedUnicode.flip();
      continueParsingInternal(partialEscapedUnicode, true);
      partialEscapedUnicode.clear();
    }

    if (state != State.ROW_FINISHED)
    {
      throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR,
                                      ErrorCode.INTERNAL_ERROR.getMessageCode(),
                                      "SFResultJsonParser2Failed: Chunk is truncated!");
    }
    currentColumn = 0;
    state = State.UNINITIALIZED;
  }
930459
public void endSession() {
		if (replayWindow != null) {
			replayWindow.removeAllElements();
		}
		replayWindow = null;
		txEncryptorSuite = rxEncryptorSuite = null;
		txIV = rxIV = null;
		txEncOut = rxEncOut = null;
		txHMAC = rxHMAC = null;
		txSessEncKey = null;
		txSessAuthKey = null;
		txSessSaltKey = null;
		rxSessEncKey = null;
		rxSessAuthKey = null;
		rxSessSaltKey = null;
		firstRtpSeq = 1;
		rollOverCounter = 0;
	}
1157086
private void closeSession(){
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("Close the session, sessionId=" + session.id + ", timeOut=" + session.timeOut);
        }
        if(! closing && getStatus().isConnected()){
            closing = true;
            if(getStatus().isAlive()){
                setStatus(ConnectionStatus.NOT_CONNECTED);
            }
            cleanupSession();
            closing = false;
        }
    }
1233300
@Override
  public void closeSession(SessionHandle sessionHandle) throws HiveSQLException {
    try {
      TCloseSessionReq req = new TCloseSessionReq(sessionHandle.toTSessionHandle());
      TCloseSessionResp resp = cliService.CloseSession(req);
      checkStatus(resp.getStatus());
    } catch (HiveSQLException e) {
      throw e;
    } catch (Exception e) {
      throw new HiveSQLException(e);
    }
  }
1276751
public synchronized void logout(final BoxSession session) {
        BoxUser user = session.getUser();
        if (user == null) {
            return;
        }
        session.clearCache();

        Context context = session.getApplicationContext();
        String userId = user.getId();

        getAuthInfoMap(session.getApplicationContext());
        BoxAuthenticationInfo info = mCurrentAccessInfo.get(userId);
        Exception ex = null;
        try {
            BoxApiAuthentication api = new BoxApiAuthentication(session);
            BoxApiAuthentication.BoxRevokeAuthRequest request = api.revokeOAuth(info.refreshToken(), session.getClientId(), session.getClientSecret());
            request.send();

        } catch (Exception e) {
            ex = e;
            BoxLogUtils.e(TAG, "logout", e);
            // Do nothing as we want to continue wiping auth info
        }
        mCurrentAccessInfo.remove(userId);

        String lastUserId = authStorage.getLastAuthentictedUserId(context);
        if (lastUserId != null) {
            authStorage.storeLastAuthenticatedUserId(null, context);
        }

        authStorage.storeAuthInfoMap(mCurrentAccessInfo, context);
        onLoggedOut(info, ex);
        info.wipeOutAuth();
    }
1210086
def disconnect(self, close=True):
        
        if not self._connected:
            # already disconnected so let's return
            return

        if close:
            for open in list(self.open_table.values()):
                open.close(False)

            for tree in list(self.tree_connect_table.values()):
                tree.disconnect()

        log.info("Session: %s - Logging off of SMB Session" % self.username)
        logoff = SMB2Logoff()
        log.info("Session: %s - Sending Logoff message" % self.username)
        log.debug(str(logoff))
        request = self.connection.send(logoff, sid=self.session_id)

        log.info("Session: %s - Receiving Logoff response" % self.username)
        res = self.connection.receive(request)
        res_logoff = SMB2Logoff()
        res_logoff.unpack(res['data'].get_value())
        log.debug(str(res_logoff))
        self._connected = False
        del self.connection.session_table[self.session_id]
575137
public final void closeSession (final String targetName) throws NoSuchSessionException , TaskExecutionException {

        getSession(targetName).logout();
        // TODO Test the removal from the map.
        sessions.remove(targetName);

        LOGGER.info("Closed the session to the iSCSI Target '" + targetName + "'.");
    }
954609
@Override
    public void close() {
        if (isClosed())
            return;

        // Set the session state to ENDED.
        setSessionState(JingleSessionStateEnded.getInstance());

        for (ContentNegotiator contentNegotiator : contentNegotiators) {

            contentNegotiator.stopJingleMediaSession();

            for (TransportCandidate candidate : contentNegotiator.getTransportNegotiator().getOfferedCandidates())
                candidate.removeCandidateEcho();

            contentNegotiator.close();
        }
        removeAsyncPacketListener();
        removeConnectionListener();
        getConnection().removeConnectionListener(connectionListener);
        LOGGER.fine("Negotiation Closed: " + getConnection().getUser() + " " + sid);
        super.close();

    }
1133225
public void close ()
        throws SQLException
    {
        if (_result != null) {
            _result.close();
            _result = null;
        }
        if (_stmt != null) {
            _stmt.close();
            _stmt = null;
        }
    }
1059966
@Override
   public void close() throws SQLException {

      switch(transactionState) {
         case CLOSED: //Segment close will ignore multiple close on same connection, but need to skip the other stuff.
            return;
         case NONE: //Autocommit never changed
            transactionState = TransactionState.CLOSED;
            break;
         default:
            try {
               resolveIncompleteTransactions();
               transactionState = TransactionState.CLOSED;
            } catch(Throwable t) {
               setLogicalCloseException(t);
            } finally {
               try {
                  if(!conn.getAutoCommit()) { //Set auto-commit
                     conn.setAutoCommit(true);
                  }
               } catch(Throwable t) {
                  setLogicalCloseException(t);
               }
            }
      }

      boolean openStatements = closeStatements();

      Throwable logicalCloseException = this.logicalCloseException; //Preserve the exception - segment will set to null. 

      segment.close(this);

      if(logicalCloseException != null) { //Now throw to the caller
         Util.throwException(logicalCloseException);
      }

      if(openStatements && openStatementPolicy == OpenStatementPolicy.REPORT) {
         throw new SQLException("Connection has open statements", JDBConnection.SQLSTATE_CONNECTION_EXCEPTION);
      }
   }
852001
private static void closeQuietly(State state) {
        // ensure only closed once and avoid race conditions
        if (state.closed.compareAndSet(false, true)) {
            // set the state fields to null after closing for garbage
            // collection purposes
            log.debug("closing rs");
            Util.closeQuietly(state.rs);
            log.debug("closing ps");
            Util.closeQuietly(state.ps);
            log.debug("closing con");
            Util.closeQuietlyIfAutoCommit(state.con);
            log.debug("closed");
        }
    }
1217778
@Override
  public void close() throws SQLException {
    if (queryExecutor == null) {
      // This might happen in case constructor throws an exception (e.g. host being not available).
      // When that happens the connection is still registered in the finalizer queue, so it gets finalized
      return;
    }
    releaseTimer();
    queryExecutor.close();
    openStackTrace = null;
  }
274153
public void close() {
        try {
            state = "CLOSING";
            if( connection != null ) {
                logger.warn("Connection not committed, rolling back.");
                rollback();
            }
            if( !events.empty() ) {
                state = "CLOSING EVENTS";
                do {
                    Execution exec = (Execution)events.pop();
                
                    try {
                        Stack<Execution> stack;
                        
                        exec.close();
                        stack = eventCache.get(exec.getClass().getName());
                        if( stack != null ) {
                            stack.push(exec);
                        }
                    }
                    catch( Throwable t ) {
                        logger.error(t.getMessage(), t);
                    }
                } while( !events.empty() );
            }
            state = "CLOSED";
        }
        finally {
            if (tracking) {
                transactions.remove(new Integer(transactionId));
            }
            events.clear();
            statements.clear();
            stackTrace = null;
        }
    }
1284858
static public LoginOutput issueSession(LoginInput loginInput)
  throws SFException, SnowflakeSQLException
  {
    return tokenRequest(loginInput, TokenRequestType.ISSUE);
  }
753121
@Override
  public void closeOperation(OperationHandle opHandle)
      throws HiveSQLException {
    sessionManager.getOperationManager().getOperation(opHandle)
    .getParentSession().closeOperation(opHandle);
    LOG.debug(opHandle + ": closeOperation");
  }