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

Spurious wakeup when waiting for a response is now handled properly #3207

Merged
merged 1 commit into from Aug 8, 2014
Jump to file or symbol
Failed to load files and symbols.
+15 −8
Diff settings

Always

Just for now

@@ -198,14 +198,7 @@ private Object waitForResponse(long time, TimeUnit unit) {
pollCount++;
try {
//we should only wait if there is any timeout. We can't call wait with 0, because it is interpreted as infinite.
if (pollTimeoutMs > 0) {
synchronized (this) {
if (response == null || response == BasicInvocation.WAIT_RESPONSE) {
wait(pollTimeoutMs);
}
}
}
pollResponse(pollTimeoutMs);
lastPollTime = Clock.currentTimeMillis() - startMs;
timeoutMs = decrementTimeout(timeoutMs, lastPollTime);
@@ -244,6 +237,20 @@ private Object waitForResponse(long time, TimeUnit unit) {
return BasicInvocation.TIMEOUT_RESPONSE;
}
private void pollResponse(final long pollTimeoutMs) throws InterruptedException {
//we should only wait if there is any timeout. We can't call wait with 0, because it is interpreted as infinite.
if (pollTimeoutMs > 0) {
long currentTimeoutMs = pollTimeoutMs;
final long waitStart = Clock.currentTimeMillis();
synchronized (this) {
while (currentTimeoutMs > 0 && (response == null || response == BasicInvocation.WAIT_RESPONSE)) {
wait(currentTimeoutMs);
currentTimeoutMs = pollTimeoutMs - (Clock.currentTimeMillis() - waitStart);
}
}
}
}
private long getMaxCallTimeoutMs() {
return basicInvocation.callTimeout > 0 ? basicInvocation.callTimeout * 2 : Long.MAX_VALUE;
}
ProTip! Use n and p to navigate between commits in a pull request.