Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If an exception occurs while launching an agent, the underlying connection and session should be closed #478

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,43 @@
return;
}

final Connection conn;
Connection conn = null;
Optional<Connection> cleanupConn;
PrintStream logger = listener.getLogger();
logInfo(computer, listener, "Launching instance: " + node.getNodeName());
Session sess = null;
try {
cleanupConn = setupConnection(node, computer, listener);
if (!cleanupConn.isPresent()) {
return;
}
conn = cleanupConn.get();
String javaExecPath = node.getJavaExecPathOrDefault();
if (!checkJavaInstalled(computer, conn, logger, listener, javaExecPath)) {
return;
}
String jenkinsDir = node.getRemoteFS();
copyAgentJar(computer, conn, listener, jenkinsDir);
String launchString = getJavaLaunchString(javaExecPath, jenkinsDir);
logInfo(computer, listener, "Launching Jenkins agent via plugin SSH: " + launchString);
final Session sess = conn.openSession();
sess = conn.openSession();
sess.execCommand(launchString);
Session finalSess = sess;
Connection finalConn = conn;
computer.setChannel(sess.getStdout(), sess.getStdin(), logger, new Channel.Listener() {
@Override
public void onClosed(Channel channel, IOException cause) {
sess.close();
conn.close();
finalSess.close();
finalConn.close();
}
});
} catch (Exception e) {
if (sess != null) {
sess.close();
}
if (conn != null) {
conn.close();

Check warning on line 318 in src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineComputerLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 283-318 are not covered by tests
}
logException(computer, listener, "Error: ", e);
}
}
Expand Down