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: Fix a possible NULL PTR after introduced timeout on waitForDone #1638

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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(1, TimeUnit.MINUTES);
waitForDoneCallback(2, TimeUnit.MINUTES);
}

// At this point, there cannot be more callback. It is safe to clean up all inflight requests.
Expand Down Expand Up @@ -573,6 +573,9 @@ private void requestCallback(AppendRowsResponse response) {
conectionRetryCountWithoutCallback = 0;
}
requestWrapper = pollInflightRequestQueue();
if (requestWrapper == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we haven't cleaned up and this happens, we should throw an exception

Maybe instead of using null, check if we've cleaned up, and don't call the method (since this is under lock anyways)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have cleaned up, then all inflight requests are all set with an exception already.
I don't think we should throw on requestCallback?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant the opposite: if we haven't cleaned up.

If during normal operations we get a callback but there's nothing in the queue, that should never happen, so we should throw (or somehow error out)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code, hope it is more straightforward.

Copy link
Contributor

@gnanda gnanda May 3, 2022

Choose a reason for hiding this comment

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

Yeah it is, but I was thinking we'd also have

doneCallback {
this.done = true;
}

and for your change in requestCallback:
if (!this.done && this.inflightRequestQueue.isEmpty()) {
// Handle this error case!
}

But since it's in the callback, that's probably more complicated than I originally thought... Should we handle that in a followup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no super good place for done, since the lock is done inside of the cleanupInflightQueue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an error message, without a response, user will probably not be able to get the actual exception.

return;
}
} finally {
this.lock.unlock();
}
Expand Down Expand Up @@ -640,11 +643,18 @@ private void doneCallback(Throwable finalStatus) {

@GuardedBy("lock")
private AppendRequestAndResponse pollInflightRequestQueue() {
AppendRequestAndResponse requestWrapper = this.inflightRequestQueue.pollFirst();
--this.inflightRequests;
this.inflightBytes -= requestWrapper.messageSize;
this.inflightReduced.signal();
return requestWrapper;
if (!this.inflightRequestQueue.isEmpty()) {
AppendRequestAndResponse requestWrapper = this.inflightRequestQueue.pollFirst();
--this.inflightRequests;
this.inflightBytes -= requestWrapper.messageSize;
this.inflightReduced.signal();
return requestWrapper;
} else {
// It is possible when requestCallback is called, the inflight queue is already drained to do
// timeout waiting
// for done.
return null;
}
}

/**
Expand Down