Skip to content

Commit 119ab91

Browse files
committed
Added Some Delays in Process and Browser Kills
I added some short delays when killing processes, in particular browsers, in the hope to achieve more graceful termination. This way, I hope to get rid of errors like https://ci.appveyor.com/project/thomasWeise/evaluator-gui/build/job/29kly0oct9akryno
1 parent 00020c9 commit 119ab91

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/main/java/org/optimizationBenchmarking/utils/tools/impl/browser/BrowserJob.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public final class BrowserJob extends ToolJob implements Closeable {
2323
*/
2424
private final boolean m_isWaitForReliable;
2525

26+
/** the time when the browser started */
27+
private final long m_startupTime;
28+
2629
/**
2730
* Create the browser job,
2831
*
@@ -49,6 +52,7 @@ public final class BrowserJob extends ToolJob implements Closeable {
4952
this.m_process = process;
5053
this.m_temp = temp;
5154
this.m_isWaitForReliable = isWaitForReliable;
55+
this.m_startupTime = System.currentTimeMillis();
5256
}
5357

5458
/**
@@ -95,6 +99,7 @@ public final boolean isWaitForReliable() {
9599
/** {@inheritDoc} */
96100
@Override
97101
public final void close() throws IOException {
102+
final long wait;
98103
ExternalProcess proc;
99104
TempDir temp;
100105

@@ -107,11 +112,32 @@ public final void close() throws IOException {
107112

108113
try {
109114
if (proc != null) {
110-
proc.close();
115+
try {
116+
// we give the browser 3s to start up before we close it
117+
wait = ((3000L - System.currentTimeMillis())
118+
+ this.m_startupTime);
119+
if (wait > 0L) {
120+
Thread.sleep(wait);
121+
}
122+
} catch (@SuppressWarnings("unused") final Throwable error) {
123+
// ignore
124+
} finally {
125+
try {
126+
proc.close();
127+
} finally {
128+
proc = null;
129+
}
130+
}
111131
}
112132
} finally {
113133
if (temp != null) {
114-
temp.close();
134+
try {
135+
Thread.sleep(100L);
136+
} catch (@SuppressWarnings("unused") final Throwable error) {
137+
// ignore
138+
} finally {
139+
temp.close();
140+
}
115141
}
116142
}
117143
}

src/main/java/org/optimizationBenchmarking/utils/tools/impl/process/ExternalProcess.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,21 @@ private final int __close(final boolean kill) throws IOException {
181181
}
182182

183183
if (shouldKill) {
184-
this.m_process.destroy();
185184
shouldMessage = true;
185+
try {
186+
// wait a bit in a last-ditch effort to let the process
187+
// gracefully terminate
188+
Thread.sleep(20L);
189+
} catch (final InterruptedException ie) {
190+
// ingore
191+
}
192+
this.m_process.destroy();
193+
try {
194+
// wait a bit in an effort to let destroy() work
195+
Thread.sleep(20L);
196+
} catch (final InterruptedException ie) {
197+
// ingore
198+
}
186199
}
187200
} catch (final Throwable t) {
188201
error = ErrorUtils.aggregateError(t, error);

0 commit comments

Comments
 (0)