Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take out a file lock on the log file #321

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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 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.)

Check warning on line 98 in src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: 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()) {

Check warning on line 101 in src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 101 is only partially covered, one branch is missing
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 @@
openStorages.remove(log);
try {
bos.close();
if (!Functions.isWindows()) {

Check warning on line 201 in src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 201 is only partially covered, one branch is missing
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
Loading