private void disconnect(Throwable reason) { try { if (session != null) { session.close(); session = null; } } catch (IOException e) { if (reason != null) { reason.addSuppressed(e); } else { LOG.error(SshdText.get().sessionCloseFailed, e); } } finally { client.stop(); client = null; } }
/** * Disconnect and cleanup. * * Must be called when done with client. */ public void close() throws IOException { try { if (session != null) { session.close(true); session = null; } if (client != null) { client.stop(); client = null; } } catch (Exception e) { log.error("Failed to close session", ExceptionUtils.getRootCauseMessage(e)); log.debug("Exception", e); throw new IOException(e); } }
protected CloseableScpClient createScpClient(ClientSession session) throws IOException { try { ScpClientCreator creator = getScpClientCreator(); ScpClient client = creator.createScpClient(Objects.requireNonNull(session, "No client session")); return createScpClient(session, client); } catch (Exception e) { log.warn("createScpClient({}) failed ({}) to create proxy: {}", session, e.getClass().getSimpleName(), e.getMessage()); try { session.close(); } catch (Exception t) { if (log.isDebugEnabled()) { log.debug("createScpClient({}) failed ({}) to close session: {}", session, t.getClass().getSimpleName(), t.getMessage()); } if (log.isTraceEnabled()) { log.trace("createScpClient(" + session + ") session close failure details", t); } e.addSuppressed(t); } throw GenericUtils.toIOException(e); } }
session.close(); } catch (Throwable t) { if (log.isDebugEnabled()) {
protected CloseableScpClient createScpClient(IOFunction<? super SimpleClient, ? extends ClientSession> sessionProvider) throws IOException { SimpleClient client = getClient(); ClientSession session = sessionProvider.apply(client); try { CloseableScpClient scp = createScpClient(session); session = null; // disable auto-close at finally block return scp; } finally { if (session != null) { session.close(); } } }
protected SftpClient createSftpClient(IOFunction<? super SimpleClient, ? extends ClientSession> sessionProvider) throws IOException { SimpleClient client = getClient(); ClientSession session = sessionProvider.apply(client); try { SftpClient sftp = createSftpClient(session); session = null; // disable auto-close at finally block return sftp; } finally { if (session != null) { session.close(); } } }
session.close(); } catch (Exception e) { if (log.isDebugEnabled()) {
@Override public void close() throws IOException { if (isOpen()) { SftpFileSystemProvider provider = provider(); String fsId = getId(); SftpFileSystem fs = provider.removeFileSystem(fsId); ClientSession session = getClientSession(); session.close(true); if ((fs != null) && (fs != this)) { throw new FileSystemException(fsId, fsId, "Mismatched FS instance for id=" + fsId); } } }
protected ClientSession authSession(ClientSession clientSession) throws IOException { ClientSession session = clientSession; IOException err = null; try { AuthFuture auth = session.auth(); auth.verify(getAuthenticationTimeout()); session = null; // disable auto-close } catch (IOException e) { err = GenericUtils.accumulateException(err, e); } finally { if (session != null) { try { session.close(); } catch (IOException e) { err = GenericUtils.accumulateException(err, e); } } } if (err != null) { throw err; } return clientSession; }
protected ClientSession authSession(ClientSession clientSession) throws IOException { ClientSession session = clientSession; IOException err = null; try { AuthFuture auth = session.auth(); auth.verify(getAuthenticationTimeout()); session = null; // disable auto-close } catch (IOException e) { err = GenericUtils.accumulateException(err, e); } finally { if (session != null) { try { session.close(); } catch (IOException e) { err = GenericUtils.accumulateException(err, e); } } } if (err != null) { throw err; } return clientSession; }
if (session != null) { try { session.close(); } catch (IOException t) { if (log.isDebugEnabled()) {
session.close(false);
sshSession.close(false);
sshSession.close(false);
assertEquals("Mismatched client events count", 1, clientEventCount.get()); assertEquals("Mismatched server events count", 1, serverEventCount.get()); s.close(false); } finally { client.stop();
assertEquals("Mismatched client events count", 1, clientEventCount.get()); assertEquals("Mismatched server events count", 1, serverEventCount.get()); s.close(false); } finally { client.stop();
assertEquals("Mismatched client events count", 1, clientEventCount.get()); assertEquals("Mismatched server events count", 1, serverEventCount.get()); s.close(false); } finally { client.stop();
private ClientSession createTestClientSession(SshServer server) throws Exception { ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, server.getPort()).verify(7L, TimeUnit.SECONDS).getSession(); try { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); ClientSession returnValue = session; session = null; // avoid 'finally' close return returnValue; } finally { if (session != null) { session.close(); } } }
private ClientSession createTestClientSession(SshServer server) throws Exception { ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, server.getPort()).verify(7L, TimeUnit.SECONDS).getSession(); try { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); ClientSession returnValue = session; session = null; // avoid 'finally' close return returnValue; } finally { if (session != null) { session.close(); } } }
private ClientSession createTestClientSession(SshServer server) throws Exception { ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, server.getPort()).verify(7L, TimeUnit.SECONDS).getSession(); try { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); ClientSession returnValue = session; session = null; // avoid 'finally' close return returnValue; } finally { if (session != null) { session.close(); } } }