Skip to content

Commit 7db56ba

Browse files
committed
Fixed versions
1 parent e8e72c1 commit 7db56ba

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

src/ssh_to_http_port_forward_pool/ssh_to_http_port_forward_pool.rs

+37-22
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,50 @@ impl SshToHttpPortForwardPool {
3434
}
3535
}
3636

37-
let listen_port = next_port();
37+
loop {
38+
let listen_port = next_port();
3839

39-
println!(
40-
"Allocating listen port: {} for http port forward {}->{}:{}",
41-
listen_port,
42-
ssh_credentials.to_string(),
43-
remote_host,
44-
remote_port
45-
);
40+
println!(
41+
"Allocating listen port: {} for http port forward {}->{}:{}",
42+
listen_port,
43+
ssh_credentials.to_string(),
44+
remote_host,
45+
remote_port
46+
);
4647

47-
let listen_host_port = format!("127.0.0.1:{}", listen_port);
48+
let listen_host_port = format!("127.0.0.1:{}", listen_port);
4849

49-
let ssh_session = SshSession::new(ssh_credentials.clone());
50+
let ssh_session = SshSession::new(ssh_credentials.clone());
5051

51-
let result = ssh_session
52-
.start_port_forward(listen_host_port, remote_host.to_string(), remote_port)
53-
.await
54-
.unwrap();
52+
let result = ssh_session
53+
.start_port_forward(listen_host_port, remote_host.to_string(), remote_port)
54+
.await;
5555

56-
let configuration = SshToHttpPortForwardConfiguration {
57-
listen_port,
58-
ssh_credentials: ssh_credentials.clone(),
59-
tunnel: result.clone(),
60-
};
56+
if let Err(err) = result {
57+
match err {
58+
my_ssh::RemotePortForwardError::CanNotExtractListenPort(_) => {
59+
panic!("Can not start port forward: {:?}", err);
60+
}
61+
my_ssh::RemotePortForwardError::CanNotBindListenEndpoint(_) => {
62+
println!("Can not bind listen port: {}", listen_port);
63+
continue;
64+
}
65+
}
66+
}
67+
68+
let result = result.unwrap();
6169

62-
let configuration = Arc::new(configuration);
70+
let configuration = SshToHttpPortForwardConfiguration {
71+
listen_port,
72+
ssh_credentials: ssh_credentials.clone(),
73+
tunnel: result.clone(),
74+
};
6375

64-
access.push(configuration.clone());
76+
let configuration = Arc::new(configuration);
6577

66-
configuration
78+
access.push(configuration.clone());
79+
80+
return configuration;
81+
}
6782
}
6883
}

0 commit comments

Comments
 (0)