diff --git a/core/src/main/java/hudson/util/StreamTaskListener.java b/core/src/main/java/hudson/util/StreamTaskListener.java index d70a905920..53b394b68a 100644 --- a/core/src/main/java/hudson/util/StreamTaskListener.java +++ b/core/src/main/java/hudson/util/StreamTaskListener.java @@ -42,6 +42,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.util.SystemProperties; import org.kohsuke.stapler.framework.io.WriterOutputStream; import javax.annotation.CheckForNull; @@ -166,12 +167,22 @@ public class StreamTaskListener extends AbstractTaskListener implements TaskList private void writeObject(ObjectOutputStream out) throws IOException { out.writeObject(new RemoteOutputStream(new CloseProofOutputStream(this.out))); out.writeObject(charset==null? null : charset.name()); + LOGGER.log(Level.FINE, null, new Throwable("serializing here with AUTO_FLUSH=" + AUTO_FLUSH)); } + /** + * Restores eager remote flushing behavior. + * By default, remote tasks are expected to call {@link PrintStream#flush} before exiting. + * This flag will ensure that no output is lost from tasks which neglect to do so, + * at the expense of heavier Remoting traffic and reduced performance. + */ + private static /* not final */ boolean AUTO_FLUSH = SystemProperties.getBoolean(StreamTaskListener.class.getName() + ".AUTO_FLUSH"); + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - out = new PrintStream((OutputStream)in.readObject(), false); + out = new PrintStream((OutputStream)in.readObject(), AUTO_FLUSH); String name = (String)in.readObject(); charset = name==null ? null : Charset.forName(name); + LOGGER.log(Level.FINE, null, new Throwable("deserializing here with AUTO_FLUSH=" + AUTO_FLUSH)); } @Override diff --git a/test/src/test/java/hudson/util/ArgumentListBuilder2Test.java b/test/src/test/java/hudson/util/ArgumentListBuilder2Test.java index fe8c19f6f7..e51dd1feea 100644 --- a/test/src/test/java/hudson/util/ArgumentListBuilder2Test.java +++ b/test/src/test/java/hudson/util/ArgumentListBuilder2Test.java @@ -39,12 +39,14 @@ import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Email; import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.LoggerRule; import com.google.common.base.Joiner; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.StringWriter; +import java.util.logging.Level; /** * @author Kohsuke Kawaguchi @@ -54,6 +56,9 @@ public class ArgumentListBuilder2Test { @Rule public JenkinsRule j = new JenkinsRule(); + @Rule + public LoggerRule logging = new LoggerRule().record(StreamTaskListener.class, Level.FINE); + /** * Makes sure {@link RemoteLauncher} properly masks arguments. */ @@ -64,8 +69,10 @@ public class ArgumentListBuilder2Test { args.add("java"); args.addMasked("-version"); - Slave s = j.createSlave(); - s.toComputer().connect(false).get(); + Slave s = j.createOnlineSlave(); + /* TODO https://github.com/jenkinsci/jenkins-test-harness/pull/127 + j.showSlaveLogs(s, logging); + */ StringWriter out = new StringWriter(); assertEquals(0,s.createLauncher(new StreamTaskListener(out)).launch().cmds(args).join());