Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to Remoting 3.15 and Cleanup issues in Channel#current() usages (
#3145)

Pulls in fixes for: JENKINS-48133, JENKINS-48055, JENKINS-37566, JENKINS-48309, JENKINS-47965, JENKINS-48130, JENKINS-37670, JENKINS-37566, JENKINS-46724 

This change also adds some missing null/closing channel checks in the core.
In some cases the change prevents spawning threads if the channel is in the invalid state.
  • Loading branch information
oleg-nenashev committed Dec 22, 2017
1 parent 8e78ab1 commit cb3990a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
9 changes: 7 additions & 2 deletions core/src/main/java/hudson/Launcher.java
Expand Up @@ -1289,6 +1289,7 @@ private static class RemoteLaunchCallable extends MasterToSlaveCallable<RemotePr
}

public RemoteProcess call() throws IOException {
final Channel channel = getOpenChannelOrFail();
Launcher.ProcStarter ps = new LocalLauncher(listener).launch();
ps.cmds(cmd).masks(masks).envs(env).stdin(in).stdout(out).stderr(err).quiet(quiet);
if(workDir!=null) ps.pwd(workDir);
Expand All @@ -1298,16 +1299,20 @@ public RemoteProcess call() throws IOException {

final Proc p = ps.start();

return Channel.current().export(RemoteProcess.class,new RemoteProcess() {
return channel.export(RemoteProcess.class,new RemoteProcess() {
public int join() throws InterruptedException, IOException {
try {
return p.join();
} finally {
// make sure I/O is delivered to the remote before we return
Channel taskChannel = null;
try {
Channel.current().syncIO();
// Sync IO will fail automatically if the channel is being closed, no need to use getOpenChannelOrFail()
taskChannel = Channel.currentOrFail();
taskChannel.syncIO();
} catch (Throwable t) {
// this includes a failure to sync, agent.jar too old, etc
LOGGER.log(Level.INFO, "Failed to synchronize IO streams on the channel " + taskChannel, t);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -1426,10 +1426,11 @@ public void doDumpExportTable( StaplerRequest req, StaplerResponse rsp ) throws

private static final class DumpExportTableTask extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
final Channel ch = getChannelOrFail();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Channel.current().dumpExportTable(pw);
pw.close();
try (PrintWriter pw = new PrintWriter(sw)) {
ch.dumpExportTable(pw);
}
return sw.toString();
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/slaves/ChannelPinger.java
Expand Up @@ -133,7 +133,8 @@ public void install(Channel channel) {

@Override
public Void call() throws IOException {
setUpPingForChannel(Channel.current(), null, pingTimeoutSeconds, pingIntervalSeconds, false);
// No sense in setting up channel pinger if the channel is being closed
setUpPingForChannel(getOpenChannelOrFail(), null, pingTimeoutSeconds, pingIntervalSeconds, false);
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/slaves/SlaveComputer.java
Expand Up @@ -867,7 +867,7 @@ public Void call() {
// ignore this error.
}

Channel.current().setProperty("slave",Boolean.TRUE); // indicate that this side of the channel is the slave side.
Channel.currentOrFail().setProperty("slave",Boolean.TRUE); // indicate that this side of the channel is the slave side.

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/FilePathFilter.java
Expand Up @@ -102,7 +102,7 @@ public final void uninstallFrom(Channel ch) {

/**
* Returns an {@link FilePathFilter} object that represents all the in-scope filters,
* or null if none is needed.
* or {@code null} if none is needed.
*/
public static @CheckForNull FilePathFilter current() {
Channel ch = Channel.current();
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/jenkins/slaves/StandardOutputSwapper.java
Expand Up @@ -39,9 +39,7 @@ public void preOnline(Computer c, Channel channel, FilePath root, TaskListener l
private static final class ChannelSwapper extends MasterToSlaveCallable<Boolean,Exception> {
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows

Channel c = Channel.current();

Channel c = getOpenChannelOrFail();
StandardOutputStream sos = (StandardOutputStream) c.getProperty(StandardOutputStream.class);
if (sos!=null) {
swap(sos);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -175,7 +175,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>remoting</artifactId>
<version>3.14</version>
<version>3.15</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -154,7 +154,7 @@ private static class Attack extends MasterToSlaveCallable<String,Exception> {
}
@Override
public String call() throws Exception {
return Channel.current().call(new ScriptLoader(path));
return getChannelOrFail().call(new ScriptLoader(path));
}
}

Expand Down
Expand Up @@ -239,7 +239,7 @@ public Integer call() throws Exception {

// Invoke backward call
try {
Channel.current().call(new Callable<String, Exception>() {
getChannelOrFail().call(new Callable<String, Exception>() {
private static final long serialVersionUID = 1L;

@Override
Expand Down

0 comments on commit cb3990a

Please sign in to comment.