mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 21:42:27 +00:00
Fixed a bug that results in unbounded memory consumption in SplittableBuildListener side buffer.
Previously, a forked life cycle resulted in MavenBuildProxy2.start/end callbacks. When a module X build forks a life cycle and comes back to building module X, end callback from the fork completion made Jenkins believe that it's not building any module, when Maven is actually coming back to building module X. So if the sequence of mojos that follow the forked mojo produces a lot of output, it can saturate memory (and even if it doesn't, Jenkins fails to capture the entire log for a module.) This fix also addresses the synchronization problem, so that when we do split the log, we make sure all the output from Maven prior to that indeed arrived to the master.
This commit is contained in:
1 parent
a67f6afe24
commit
d457c3a8aa
4 files changed
+43
-25
No files matched your search
@@ -586,36 +586,40 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
|
||||
recordMojoFailed(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.execution.ExecutionListener#forkedProjectStarted(org.apache.maven.execution.ExecutionEvent)
|
||||
/*
|
||||
Forked life cycle handling
|
||||
--------------------------
|
||||
|
||||
As discussed in MavenBuildProxy2, Jenkins has a simplistic view of Maven build sequence,
|
||||
and in particular it doesn't recognize the forked life cycle as a first-class citizen.
|
||||
So to map the reality with the Jenkins' simplified model, we don't report forked project as
|
||||
a separate module start/end.
|
||||
|
||||
Doing so would require that we remember the nesting, and when the forking is over, we need to
|
||||
tell MavenBuildProxy2 of the right module that its build has resumed.
|
||||
*/
|
||||
|
||||
public void forkedProjectStarted( ExecutionEvent event ) {
|
||||
LOGGER.fine( "forkedProjectStarted " + event.getProject().getGroupId() + ":"
|
||||
+ event.getProject().getArtifactId() + event.getProject().getVersion() );
|
||||
recordProjectStarted(event);
|
||||
// recordProjectStarted(event);
|
||||
this.eventLogger.forkedProjectStarted( event );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.execution.ExecutionListener#forkedProjectSucceeded(org.apache.maven.execution.ExecutionEvent)
|
||||
*/
|
||||
public void forkedProjectSucceeded( ExecutionEvent event ) {
|
||||
LOGGER.fine( "forkedProjectSucceeded "
|
||||
+ event.getProject().getGroupId() + ":"
|
||||
+ event.getProject().getArtifactId()
|
||||
+ event.getProject().getVersion());
|
||||
recordProjectSucceeded(event);
|
||||
// recordProjectSucceeded(event);
|
||||
this.eventLogger.forkedProjectSucceeded( event );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.execution.ExecutionListener#forkedProjectFailed(org.apache.maven.execution.ExecutionEvent)
|
||||
*/
|
||||
public void forkedProjectFailed( ExecutionEvent event ) {
|
||||
LOGGER.fine("forkedProjectFailed " + event.getProject().getGroupId()
|
||||
+ ":" + event.getProject().getArtifactId()
|
||||
+ ":" + event.getProject().getVersion());
|
||||
recordProjectFailed(event);
|
||||
// recordProjectFailed(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -517,11 +517,11 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
|
||||
* Before we touch I/O streams, we need to make sure all the remote I/O operations are locally completed,
|
||||
* or else we end up switching the log traffic at unaligned moments.
|
||||
*/
|
||||
private void sync() {
|
||||
private void sync() throws IOException {
|
||||
try {
|
||||
Channel ch = Channel.current();
|
||||
if (ch!=null)
|
||||
ch.syncLocalIO();
|
||||
listener.synchronizeOnMark(ch);
|
||||
} catch (InterruptedException e) {
|
||||
// our signature doesn't allow us to throw InterruptedException, so we process it later
|
||||
Thread.currentThread().interrupt();
|
||||
|
||||
@@ -33,6 +33,11 @@ package hudson.maven;
|
||||
public interface MavenBuildProxy2 extends MavenBuildProxy {
|
||||
/**
|
||||
* Notifies that the build has entered a module.
|
||||
*
|
||||
* Jenkins has a somewhat simplified view of the sequence of events in a Maven build.
|
||||
* Namely, a Maven build can be building a particular Maven module, and start and end marks that boundary.
|
||||
* Note that Maven can be in a state that it's not building any module, for example when executing an aggregator mojo,
|
||||
* and start/end cannot be nested (which right now means a forked lifecycle doesn't result in the event firing.)
|
||||
*/
|
||||
void start();
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import hudson.model.BuildListener;
|
||||
import hudson.model.Cause;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.StreamBuildListener;
|
||||
import hudson.remoting.Callable;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.util.AbstractTaskListener;
|
||||
import jenkins.util.MarkFindingOutputStream;
|
||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
@@ -126,23 +128,21 @@ final class SplittableBuildListener extends AbstractTaskListener implements Buil
|
||||
* a synchronization needs to happen when we switch the side OutputStream.
|
||||
*
|
||||
* <p>
|
||||
* This method is a part of the protocol to do that. First,
|
||||
* To ensure that the output is split
|
||||
* at the right moment,
|
||||
* This method does that synchronization.
|
||||
*/
|
||||
public int byMyMark() {
|
||||
public void synchronizeOnMark(Channel ch) throws IOException, InterruptedException {
|
||||
synchronized (markCountLock) {
|
||||
return markCount;
|
||||
int start = markCount;
|
||||
|
||||
// have the remote send us a mark
|
||||
ch.call(new SendMark());
|
||||
|
||||
// and block until we receive a mark
|
||||
while (markCount==start)
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
public void waitForMark(int n) throws InterruptedException {
|
||||
synchronized (markCountLock) {
|
||||
while (markCount==n)
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSideOutputStream(OutputStream os) throws IOException {
|
||||
synchronized (lock()) {
|
||||
if(os==null) {
|
||||
@@ -217,4 +217,13 @@ final class SplittableBuildListener extends AbstractTaskListener implements Buil
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SendMark implements Callable<Void, IOException> {
|
||||
public Void call() throws IOException {
|
||||
// write a mark
|
||||
System.out.write(MARK);
|
||||
System.out.flush();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user