-
Notifications
You must be signed in to change notification settings - Fork 75
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
[JENKINS-56446] Do not permanently close the log stream in FileLogStorage if an interrupted thread attempts to write to it #296
Conversation
…rupted thread attempts to write to it
close(stepLog); | ||
overall.getLogger().println("overall 2"); | ||
close(overall); | ||
assertOverallLog(0, lines("overall 1", "<span class=\"pipeline-node-1\">step 1", "</span>overall 2"), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fix, only overall 1
gets written to the log, and you get the "failed to flush" messages in the JENKINS ticket from BuildWatcher
in the log as it copies the output which calls maybeFlush
.
src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks straightforward.
Many thanks for tracking this down! Out of curiosity, do you know what about the previously posted reproduction scenarios would lead to a thread interruption?
Disabling automerge since I noticed workflow-api-plugin/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java Line 95 in e929275
JenkinsSessionRule seem to check anything interesting about log text. I probably need to either add a cross-restart test to LogStorageTestBase , or introduce a new test case specifically about FileLogStorage verifying that the append mode actually appends and that the index keeps up accordingly.
|
No, I do not. @jgreffe and I saw this same issue with an alternate implementation of In this particular case I am prototyping some unrelated changes in |
… the FileLogStorage monitor already held
It is a good question. It is very unfortunate that |
Is this something you are actively working on? If not I can look into it, but I will probably not be able to get to it today. |
Yes. Actually backing up a bit to try to let |
Never mind. After exploring a bit, I found that in fact changing workflow-api-plugin/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java Line 88 in 1679fa2
false causes workflow-api-plugin/src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java Lines 139 to 143 in 1679fa2
workflow-api-plugin/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java Line 97 in b763772
0 .
|
See JENKINS-56446.
While investigating other changes I finally tracked down an issue I have seen before where the main Pipeline log gets closed for some unknown reason, blocking all further writes. I will look for a JENKINS ticket shortly, and I know there is a CloudBees-internal ticket about this issue.
The problem is that
FileLogStorage.checkId
uses aFileChannel
method to get the current position of the log whenever the log output switches from one step to another.FileChannel
methods close the channel, and in this case the stream it was derived from, if the thread is interrupted when performing any IO operations. This behavior is undesirable for Pipeline, because it means that any thread writing log output for a step has the ability to inadvertently close the log stream permanently if that thread is interrupted, even if the interruption is expected/controlled (e.g. thetimeout
step).For some additional context, I also saw a similar issue with another implementation of
LogStorage
that attempted to useFileChannel
, and in that case we avoided it completely in favor of plainFileOutputStream
to fix the issue.Testing done
Submitter checklist