diff --git a/cli/src/main/java/hudson/cli/FlightRecorderInputStream.java b/cli/src/main/java/hudson/cli/FlightRecorderInputStream.java index 5a1167c4fdc5..41d7a719dd09 100644 --- a/cli/src/main/java/hudson/cli/FlightRecorderInputStream.java +++ b/cli/src/main/java/hudson/cli/FlightRecorderInputStream.java @@ -21,7 +21,7 @@ class FlightRecorderInputStream extends InputStream { * Size (in bytes) of the flight recorder ring buffer used for debugging remoting issues. * @since 2.41 */ - static final int BUFFER_SIZE = Integer.getInteger("hudson.remoting.FlightRecorderInputStream.BUFFER_SIZE", 1024 * 1024); + static final int BUFFER_SIZE = Integer.getInteger("hudson.remoting.FlightRecorderInputStream.BUFFER_SIZE", 1024); private final InputStream source; private ByteArrayRingBuffer recorder = new ByteArrayRingBuffer(BUFFER_SIZE); diff --git a/test/src/test/java/hudson/cli/PlainCLIProtocolTest.java b/test/src/test/java/hudson/cli/PlainCLIProtocolTest.java new file mode 100644 index 000000000000..d9081ed6910f --- /dev/null +++ b/test/src/test/java/hudson/cli/PlainCLIProtocolTest.java @@ -0,0 +1,61 @@ +package hudson.cli; + +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; + +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.logging.Level; +import org.junit.Rule; +import org.junit.jupiter.api.Test; +import org.jvnet.hudson.test.LoggerRule; + +public class PlainCLIProtocolTest { + + @Rule public LoggerRule logger = new LoggerRule().record(PlainCLIProtocol.class, Level.FINE).capture(50); + + @Test + public void streamCorruption() throws Exception { + final PipedOutputStream upload = new PipedOutputStream(); + final PipedOutputStream download = new PipedOutputStream(); + + class Server extends PlainCLIProtocol.ServerSide { + Server() throws IOException { + super(new PlainCLIProtocol.FramedOutput(download)); + } + + @Override + protected void onArg(String text) {} + + @Override + protected void onLocale(String text) {} + + @Override + protected void onEncoding(String text) {} + + @Override + protected synchronized void onStart() {} + + @Override + protected void onStdin(byte[] chunk) throws IOException {} + + @Override + protected void onEndStdin() throws IOException {} + + @Override + protected void handleClose() {} + } + + Server server = new Server(); + new PlainCLIProtocol.FramedReader(server, new PipedInputStream(upload)).start(); + // Trigger corruption + upload.write(0xFF); + upload.write(0xFF); + upload.write(0xFF); + upload.write(0xFF); + upload.flush(); + await().until(logger::getMessages, hasItem(containsString("Read back: 0xff 0xff 0xff 0xff"))); + } +}