Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Functions;
import hudson.console.AnnotatedLargeText;
import hudson.console.ConsoleAnnotationOutputStream;
import hudson.model.BuildListener;
Expand Down Expand Up @@ -94,6 +95,14 @@ private FileLogStorage(File log) {
private synchronized void open() throws IOException {
if (os == null) {
os = new FileOutputStream(log, true);
// TODO mandatory file locks break log reading on Windows (see FileLogStorageTest.smokes etc.)
// And LargeText offers no control over how FileSession works, so cannot share the channel.
// Could instead lock the index file, then use openStorages to ensure that readers reuse the channel.
if (!Functions.isWindows()) {
LOGGER.fine(() -> "locking " + log + "…");
os.getChannel().lock();
LOGGER.fine(() -> "…locked " + log);
}
osStartPosition = log.length();
cos = new CountingOutputStream(os);
bos = LogStorage.wrapWithAutoFlushingBuffer(cos);
Expand Down Expand Up @@ -189,6 +198,9 @@ private final class IndexOutputStream extends OutputStream {
openStorages.remove(log);
try {
bos.close();
if (!Functions.isWindows()) {
LOGGER.fine(() -> "closed " + log + " which should have released its lock");
}
} finally {
indexOs.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@

import hudson.model.TaskListener;
import java.io.File;
import java.util.logging.Level;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.LoggerRule;

public class FileLogStorageTest extends LogStorageTestBase {

@ClassRule public static LoggerRule fineLogging = new LoggerRule();
@Rule public TemporaryFolder tmp = new TemporaryFolder();
private File log;

Expand All @@ -56,6 +60,7 @@ public class FileLogStorageTest extends LogStorageTestBase {
}

@Test public void interruptionDoesNotCloseStream() throws Exception {
fineLogging.record(FileLogStorage.class, Level.FINE);
LogStorage ls = createStorage();
TaskListener overall = ls.overallListener();
overall.getLogger().println("overall 1");
Expand Down