Skip to content

Commit

Permalink
Fix connect timeout that was not used.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludup committed Oct 17, 2024
1 parent 490b3a6 commit 28ed204
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ protected final Connection<SshClientContext> doConnect(String hostname, int port
if(onConfigure.isPresent())
onConfigure.get().accept(sshContext);
try {
ConnectRequestFuture future = sshContext.getEngine().connect(hostname, port, sshContext);
ConnectRequestFuture future = sshContext.getEngine().connect(hostname, port, sshContext, connectTimeout);
future.waitFor(connectTimeout);
if(!future.isSuccess()) {
var lastErr = future.getLastError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,38 +518,30 @@ public void restart(boolean graceful, long forceAfterMs) throws IOException {

}

public <K extends ProtocolContext> ConnectRequestFuture connect(String hostToConnect, int portToConnect, K protocolContext) throws SshException, IOException {
public <K extends ProtocolContext> ConnectRequestFuture connect(String hostToConnect, int portToConnect, K protocolContext, long timeout) throws SshException, IOException {

SocketChannel socketChannel = SocketChannel.open();

socketChannel.configureBlocking(true);
socketChannel.configureBlocking(true);
socketChannel.socket().setTcpNoDelay(true);

final ConnectRequestFuture future;
boolean connected;

switch(protocolContext.getProxyType()) {
case NONE:
future = new ConnectRequestFuture(hostToConnect, portToConnect);
connected = socketChannel.connect(new InetSocketAddress(hostToConnect, portToConnect));
socketChannel.socket().connect(new InetSocketAddress(hostToConnect, portToConnect), (int)timeout);
break;
default:
future = new ConnectRequestFuture(protocolContext.getProxyHostname(), protocolContext.getProxyPort());
connected = socketChannel.connect(new InetSocketAddress(protocolContext.getProxyHostname(), protocolContext.getProxyPort()));
socketChannel.socket().connect(new InetSocketAddress(protocolContext.getProxyHostname(), protocolContext.getProxyPort()), (int)timeout);
}

if(connected) {
processOpenSocket(socketChannel, protocolContext, hostToConnect, portToConnect);
socketChannel.configureBlocking(false);
registerClientConnection(protocolContext, socketChannel, future);

} else {

// Register the connector and we will confirm once we have connected
registerConnector(new DaemonClientConnector(protocolContext, socketChannel, future, hostToConnect, portToConnect), socketChannel);
}
processOpenSocket(socketChannel, protocolContext, hostToConnect, portToConnect);
socketChannel.configureBlocking(false);
registerClientConnection(protocolContext, socketChannel, future);

return future;
return future;
}

private void sendHTTPProxyRequest(SocketChannel channel, ProtocolContext protocolContext, String hostToConnect, int portToConnect) throws UnsupportedEncodingException, IOException {
Expand Down

0 comments on commit 28ed204

Please sign in to comment.