Skip to content
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

fix: A stuck when the client fail to get DoneCallback #1637

Merged
merged 5 commits into from
May 2, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private void appendLoop() {
// We can close the stream connection and handle the remaining inflight requests.
if (streamConnection != null) {
this.streamConnection.close();
waitForDoneCallback();
waitForDoneCallback(1, TimeUnit.MINUTES);
}

// At this point, there cannot be more callback. It is safe to clean up all inflight requests.
Expand All @@ -491,9 +491,10 @@ private boolean waitingQueueDrained() {
}
}

private void waitForDoneCallback() {
private void waitForDoneCallback(long duration, TimeUnit timeUnit) {
log.fine("Waiting for done callback from stream connection. Stream: " + streamName);
while (true) {
long deadline = System.nanoTime() + timeUnit.toNanos(duration);
while (System.nanoTime() <= deadline) {
this.lock.lock();
try {
if (connectionFinalStatus != null) {
Expand All @@ -505,6 +506,14 @@ private void waitForDoneCallback() {
}
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
this.lock.lock();
if (connectionFinalStatus == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar w/java, but do we need the try {} finallly {lock.unlock();} around this block like I see in other places, or is that unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

connectionFinalStatus =
new StatusRuntimeException(
Status.fromCode(Code.CANCELLED).withDescription("Timeout waiting for DoneCallback."));
}
this.lock.unlock();
return;
}

private AppendRowsRequest prepareRequestBasedOnPosition(
Expand Down