Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

chore: demonstrate how to handle an inflight request timeout exception#2441

Merged
agrawal-siddharth merged 2 commits into
googleapis:mainfrom
agrawal-siddharth:handleTimeout
Mar 8, 2024
Merged

chore: demonstrate how to handle an inflight request timeout exception#2441
agrawal-siddharth merged 2 commits into
googleapis:mainfrom
agrawal-siddharth:handleTimeout

Conversation

@agrawal-siddharth

@agrawal-siddharth agrawal-siddharth commented Mar 8, 2024

Copy link
Copy Markdown
Contributor

The request with the specific timeout exception, along with any aborted requests, must simply be caught and retried on a new StreamWriter.

If using connection pooling, creation of the new StreamWriter will be handled automatically by the connection pool. Otherwise, we manually create and switch to using a new JsonStreamWriter before re-sending the request.

@product-auto-label product-auto-label Bot added the size: m Pull request size is medium. label Mar 8, 2024
@product-auto-label product-auto-label Bot added the api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. label Mar 8, 2024
@agrawal-siddharth agrawal-siddharth force-pushed the handleTimeout branch 2 times, most recently from e171ae7 to 5b4d15c Compare March 8, 2024 01:46
} else if (throwable instanceof StreamWriterClosedException) {
StreamWriterClosedException swce = (StreamWriterClosedException) throwable;
Status status = swce.getStatus();
if (status.getCode() == Code.ABORTED) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why we only retry on aborted error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The StreamWriterClosedException can be returned when:

(a) user has already called close() on the ConnectionWorker. This has code FAILED_PRECONDITION set. In this case the client could retry, but must be using a different ConnectionWorker. In the sample code, we don't create a new JsonStreamWriter if user had already closed it. So if we did a retry on the same ConnectionWorker, it would cause an infinite loop. We would have to change the existing logic to support this.

(b) connection has a final status set on it, indicating an error occurred. This has code FAILED_PRECONDTION set. In this case the client should retry, but using a different ConnectionWorker. So this case would be ok to retry. However, we can't distinguish it from case (a).

(c) connection has been closed, but there was an inflight request. This has code FAILED_PRECONDTION set. In this case the client should retry, but using a different ConnectionWorker. So this case would be ok to retry. However, we can't distinguish it from case (a).

(d) connection has been closed and there was an error, and this is the second or later inflight request. This has code ABORTED set. In this case the client should retry, but using a different ConnectionWorker. So this case would be ok to retry. Currently this is the only case we handle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It sounds like we should distinguish the user closed case and not to retry there. Since we still hold the previous writer object, we could call writer.IsUserClosed and not to retry on that case only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@product-auto-label product-auto-label Bot added size: s Pull request size is small. and removed size: m Pull request size is medium. labels Mar 8, 2024
@agrawal-siddharth agrawal-siddharth added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 8, 2024
@agrawal-siddharth agrawal-siddharth added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 8, 2024
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 8, 2024
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Mar 8, 2024
@agrawal-siddharth agrawal-siddharth merged commit cc9fdfd into googleapis:main Mar 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants