Skip to content

Commit

Permalink
[JENKINS-33425] Better timer cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Mar 9, 2016
1 parent 0bd03f2 commit 42ff785
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
import hudson.views.MyViewsTabBar;
import hudson.views.ViewsTabBar;
import hudson.widgets.Widget;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import jenkins.ExtensionComponentSet;
import jenkins.ExtensionRefreshException;
import jenkins.InitReactorRunner;
Expand Down Expand Up @@ -3013,7 +3015,7 @@ private void _cleanUpShutdownUDPBroadcast(List<Throwable> errors) {

private void _cleanUpCloseDNSMulticast(List<Throwable> errors) {
if(dnsMultiCast!=null) {
LOGGER.log(Level.FINE, "Closing DNS multi-cast service-discovery");
LOGGER.log(Level.FINE, "Closing DNS Multicast service");
try {
dnsMultiCast.close();
} catch (OutOfMemoryError e) {
Expand Down Expand Up @@ -3053,11 +3055,23 @@ private void _cleanUpInterruptReloadThread(List<Throwable> errors) {
private void _cleanUpShutdownTriggers(List<Throwable> errors) {
LOGGER.log(Level.FINE, "Shutting down triggers");
try {
java.util.Timer timer = Trigger.timer;
final java.util.Timer timer = Trigger.timer;
if (timer != null) {
timer.cancel();
final CountDownLatch latch = new CountDownLatch(1);
timer.schedule(new TimerTask() {
@Override
public void run() {
timer.cancel();
latch.countDown();
}
}, 0);
if (latch.await(10, TimeUnit.SECONDS)) {
LOGGER.log(Level.FINE, "Triggers shut down successfully");
} else {
timer.cancel();
LOGGER.log(Level.INFO, "Gave up waiting for triggers to finish running");
}
}
// TODO: how to wait for the completion of the last job?
Trigger.timer = null;
} catch (OutOfMemoryError e) {
// we should just propagate this, no point trying to log
Expand Down

0 comments on commit 42ff785

Please sign in to comment.