Skip to content

Commit

Permalink
[RESOLVED JENKINS-4797] Added a timeout for the tool process. The tim…
Browse files Browse the repository at this point in the history
…eout is default set to 10 minutes, but can be changed.
  • Loading branch information
redsolo committed Nov 16, 2011
1 parent 74fd646 commit 82e8177
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
8 changes: 1 addition & 7 deletions pom.xml
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.319</version>
<version>1.363</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -77,12 +77,6 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>hudson-test-harness</artifactId>
<version>1.318</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -8,7 +8,9 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.List;
import java.util.concurrent.TimeUnit;

import net.sf.json.JSONObject;

Expand All @@ -22,6 +24,7 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.FilePath.FileCallable;
import hudson.Proc;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
Expand Down Expand Up @@ -78,7 +81,10 @@ private boolean checkForFileUsage(AbstractBuild<?, ?> build, BuildListener liste
try {
listener.getLogger().println("Searching for locked files in workspace.");
FilePath workspace = build.getWorkspace();
List<FileUsageDetails> list = workspace.act(new GetUsedFiles(command, new StreamBuildListener(listener.getLogger())));
List<FileUsageDetails> list = workspace.act(
new GetUsedFiles(command,
new StreamBuildListener(listener.getLogger(), Charset.defaultCharset()),
getDescriptor().getDefaultToolTimeout()));
if (list.size() > 0) {
build.getActions().add(new LockedFilesReportAction(build, list));
listener.error("Build was failed as the workspace contained files that were locked by another process. See Locked files report for more information.");
Expand All @@ -101,18 +107,26 @@ static class GetUsedFiles implements FileCallable<List<FileUsageDetails>> {
private static final long serialVersionUID = 1L;
private final FindFilesInUseCommand command;
private final StreamBuildListener listener;
public GetUsedFiles(FindFilesInUseCommand command, StreamBuildListener listener) {
private final int defaultToolTimeout;
public GetUsedFiles(FindFilesInUseCommand command, StreamBuildListener listener, int defaultToolTimeout) {
this.command = command;
this.listener = listener;
this.defaultToolTimeout = defaultToolTimeout;
}

public List<FileUsageDetails> invoke(File f, VirtualChannel channel) throws IOException {
String workspacePath = f.getCanonicalPath();
ByteArrayOutputStream commandOutput = new ByteArrayOutputStream();
BufferedReader reader = null;
try {
int result = new Launcher.LocalLauncher(listener).launch().cmds(command.getArguments(workspacePath)).
stdout(new ForkOutputStream(commandOutput, listener.getLogger())).start().join();
int result;
Proc proc = new Launcher.LocalLauncher(listener).launch().cmds(command.getArguments(workspacePath)).
stdout(new ForkOutputStream(commandOutput, listener.getLogger())).start();
if (defaultToolTimeout == 0) {
result = proc.join();
} else {
result = proc.joinWithTimeout(defaultToolTimeout * 60, TimeUnit.SECONDS, listener);
}
reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(commandOutput.toByteArray())));
return command.parseOutput(result, reader, workspacePath);
} catch (InterruptedException e) {
Expand All @@ -129,10 +143,12 @@ public List<FileUsageDetails> invoke(File f, VirtualChannel channel) throws IOEx
@Extension
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {

private String handleExecutable;
private String handleExecutable;
private int defaultToolTimeout;
public DescriptorImpl() {
super(LockedFilesReporter.class);
handleExecutable = "handle.exe";
defaultToolTimeout = 10;
load();
}

Expand Down Expand Up @@ -164,5 +180,13 @@ public String getHandleExecutable() {
public void setHandleExecutable(String handleExecutable) {
this.handleExecutable = handleExecutable;
}

public int getDefaultToolTimeout() {
return defaultToolTimeout;
}

public void setDefaultToolTimeout(int defaultToolTimeout) {
this.defaultToolTimeout = defaultToolTimeout;
}
}
}
@@ -1,7 +1,12 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="Locked files report" help="/plugin/googleanalytics/profileid.html">
<f:entry title="Handle executable" field="handleExecutable">
<f:section title="Locked files report">
<f:entry title="Handle executable" field="handleExecutable" help="/plugin/locked-files-report/help-handleExecutable.html">
<f:textbox default="handle.exe"/>
</f:entry>
<f:advanced>
<f:entry title="Default tool timeout in minutes" field="defaultToolTimeout" help="/plugin/locked-files-report/help-defaultToolTimeout.html">
<f:textbox default="10"/>
</f:entry>
</f:advanced>
</f:section>
</j:jelly>
9 changes: 9 additions & 0 deletions src/main/webapp/help-defaultToolTimeout.html
@@ -0,0 +1,9 @@
<div>
<p>
There has been reports with the Windows handle tool that it does not timeout due to an unknown issue. To make sure that the
build continues even if the tool locks up it is possible to set a timeout. The timeout is specified in minutes and should be
long enough to let the tool finish normally. Default value is 10 minutes, and 0 minutes means that the tool will not timeout and may
hang the build. This was introduced to fix the <a href="https://issues.jenkins-ci.org/browse/JENKINS-4797">JENKINS-4797</a> issue
and has only occurred on Windows.
</p>
</div>

0 comments on commit 82e8177

Please sign in to comment.