-
Notifications
You must be signed in to change notification settings - Fork 73
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
Stop agents before exiting test cases, and reliably close all_*.log
when agents exit
#624
Changes from 16 commits
8ecc1f3
7fcc00b
06190e8
201f598
7449467
6aafeb3
173a6c4
b70d8db
bbc4d5b
cb46c86
2a9b6e1
e04d1dd
122ee27
e23e0ba
6e736cf
f9aa9e6
d576db6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,7 @@ private void setFile(File file) throws FileNotFoundException { | |
parentFile.mkdirs(); | ||
} | ||
|
||
StreamUtils.closeQuietly(null); // ensure class is loaded so close() can succeed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does nothing but loads this class. Otherwise there can occasionally be a |
||
boolean success = false; | ||
FileOutputStream fos = null; | ||
BufferedOutputStream bos = null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -862,6 +862,15 @@ | |
// avoid double installation of the handler. JNLP agents can reconnect to the controller multiple times | ||
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name, | ||
// not by their identity. | ||
closeAll(); | ||
Runtime.getRuntime().addShutdownHook(new Thread(LogInitializer::closeAll, "close log handlers")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensures that the file handle is closed before the JVM exits. Likely irrelevant on Linux, but seems to matter on Windows, where the OS will release mandatory file locks “sometime” after the process exits but not necessarily quickly enough for a test. |
||
LogHolder.AGENT_LOG_HANDLER.setLevel(level); | ||
LogHolder.AGENT_LOG_HANDLER.setDirectory(new File(rootPath.getRemote(), SUPPORT_DIRECTORY_NAME), "all"); | ||
ROOT_LOGGER.addHandler(LogHolder.AGENT_LOG_HANDLER); | ||
return null; | ||
} | ||
|
||
private static void closeAll() { | ||
for (Handler h : ROOT_LOGGER.getHandlers()) { | ||
if (h.getClass() | ||
.getName() | ||
|
@@ -874,10 +883,6 @@ | |
} | ||
} | ||
} | ||
LogHolder.AGENT_LOG_HANDLER.setLevel(level); | ||
LogHolder.AGENT_LOG_HANDLER.setDirectory(new File(rootPath.getRemote(), SUPPORT_DIRECTORY_NAME), "all"); | ||
ROOT_LOGGER.addHandler(LogHolder.AGENT_LOG_HANDLER); | ||
return null; | ||
} | ||
} | ||
|
||
|
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.
jenkinsci/jenkins-test-harness#922
Previously, the agent JVM launched by
SimpleCommandLauncher
(JenkinsRule.createSlave
/.createOnlineSlave
) would be terminated when theComputer
was disconnected as part ofJenkins.cleanUp
, but asynchronously and possible slightly later, whenTemporaryDirectoryAllocator
was already trying to clean up.