提交 dc716da1 编写于 作者: K Kohsuke Kawaguchi

[JENKINS-11458] Channel.current() is only available from the thread that's...

[JENKINS-11458] Channel.current() is only available from the thread that's executing the remote call, and that's why we saw this original error, when Maven uses a thread pool to call into this method from another worker thread.
上级 0d7bb99b
......@@ -23,6 +23,9 @@
*/
package hudson.maven;
import hudson.matrix.JDKAxis;
import hudson.matrix.LabelAxis;
import hudson.matrix.TextAxis;
import hudson.model.BuildListener;
import hudson.model.Executor;
import hudson.model.Result;
......@@ -163,13 +166,21 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
protected class FilterImpl extends MavenBuildProxy2.Filter<MavenBuildProxy2> implements Serializable {
private MavenBuildInformation mavenBuildInformation;
private Channel channel;
/**
* Maven can internally use multiple threads to call {@link #executeAsync(BuildCallable)},
* making it impossible to rely on {@code Channel#current()} at the point of call, so
* instead we capture it when we get deserialized into Maven JVM.
* In other cases, we create FilterImpl inside Maven JVM, so we take it as a constructor.
* See JENKINS-11458
*/
private transient Channel channel;
public FilterImpl(MavenBuildProxy2 core, MavenBuildInformation mavenBuildInformation) {
super(core);
this.mavenBuildInformation = mavenBuildInformation;
}
public FilterImpl(MavenBuildProxy2 core, MavenBuildInformation mavenBuildInformation, Channel channel) {
super(core);
this.mavenBuildInformation = mavenBuildInformation;
......@@ -181,24 +192,21 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
@Override
public void executeAsync(final BuildCallable<?,?> program) throws IOException {
Channel ch = this.channel != null ? this.channel : Channel.current();
if (ch == null) {
throw new NullPointerException("current channel not available!");
}
recordAsynchronousExecution(
ch.callAsync(
channel.callAsync(
new AsyncInvoker(core,program)));
}
private static final long serialVersionUID = 1L;
public MavenBuildInformation getMavenBuildInformation()
{
public MavenBuildInformation getMavenBuildInformation() {
return mavenBuildInformation;
}
}
public Object readResolve() {
channel = Channel.current();
return this;
}
private static final long serialVersionUID = 1L;
}
}
......@@ -89,7 +89,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
sourceProxies = new HashMap<ModuleName, ProxyImpl2>(proxies);
this.proxies = new HashMap<ModuleName, MavenBuildProxy2>(proxies);
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet())
e.setValue(new FilterImpl(e.getValue(), this.mavenBuildInformation, Channel.current()));
e.setValue(new FilterImpl(e.getValue(), this.mavenBuildInformation));
this.reporters.putAll( reporters );
}
......@@ -210,7 +210,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
this.proxies = new ConcurrentHashMap<ModuleName, MavenBuildProxy2>(maven3Builder.proxies);
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet())
{
e.setValue(maven3Builder.new FilterImpl(e.getValue(), maven3Builder.mavenBuildInformation));
e.setValue(maven3Builder.new FilterImpl(e.getValue(), maven3Builder.mavenBuildInformation, Channel.current()));
executedMojosPerModule.put( e.getKey(), new CopyOnWriteArrayList<ExecutedMojo>() );
}
this.reporters.putAll( new ConcurrentHashMap<ModuleName, List<MavenReporter>>(maven3Builder.reporters) );
......
......@@ -322,13 +322,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
recordAsynchronousExecution(Channel.current().callAsync(new AsyncInvoker(core,program)));
}
public MavenBuildInformation getMavenBuildInformation()
{
return super.core.getMavenBuildInformation();
}
private static final long serialVersionUID = 1L;
}
@Override
......
......@@ -240,6 +240,10 @@ public interface MavenBuildProxy {
core.setExecutedMojos(executedMojos);
}
public MavenBuildInformation getMavenBuildInformation() {
return core.getMavenBuildInformation();
}
private static final long serialVersionUID = 1L;
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册