Skip to content

Commit 669877f

Browse files
committed
If someone had managed to somehow interrupt the private thread running in SingleShotLinearTimer, it would busy wait out the rest of its remaining time. Now it goes back to sleep, then restores the interrupt flag. Shouldn't be possible outside of a debugger either way.
1 parent 6a086ff commit 669877f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/main/java/com/rabbitmq/utility/SingleShotLinearTimer.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,27 @@ public TimerThread(long timeoutMillisec) {
7272
public void run() {
7373
try {
7474
long now;
75-
while ((now = System.nanoTime() / NANOS_IN_MILLI) < _runTime) {
76-
if (_task == null) break;
75+
boolean wasInterrupted = false;
76+
try {
77+
while ((now = System.nanoTime() / NANOS_IN_MILLI) < _runTime) {
78+
if (_task == null) break;
7779

78-
try {
79-
synchronized(this) {
80-
wait(_runTime - now);
80+
try {
81+
synchronized(this) {
82+
wait(_runTime - now);
83+
}
84+
} catch (InterruptedException e) {
85+
wasInterrupted = true;
8186
}
82-
} catch (InterruptedException e) {
83-
Thread.currentThread().interrupt();
8487
}
88+
} finally {
89+
if (wasInterrupted)
90+
Thread.currentThread().interrupt();
8591
}
8692

8793
Runnable task = _task;
8894
if (task != null) {
89-
task.run();
95+
task.run();
9096
}
9197

9298
} finally {

0 commit comments

Comments
 (0)