GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: improve information on CancellationException for LROs by diegomarquezp · Pull Request #2236 · googleapis/sdk-platform-java

This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Conversation

@diegomarquezp

@diegomarquezp diegomarquezp commented Nov 10, 2023

Copy link
Copy Markdown
Contributor

Fixes #1858
When a LRO runs out of retries/time, it throws a CancellationException that is then swallowed by guava's AbstractFuture, meaning there is no simple way to bubble up a custom exception with message.

This approach uses a logger with a message that points to LRO documentation to ensure the user is informed on what they can do about this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
diegomarquezp added 9 commits November 10, 2023 18:47
@diegomarquezp
fix: point to documentation on LRO CancelledException
624660c
@diegomarquezp
mvn fmt:format
a4483ee
@diegomarquezp
add test for http IT in LRO
fa781ea
@diegomarquezp
format code
937e4e6
@diegomarquezp
use final variable on LRO cancellation
9f17544
@diegomarquezp
Wrap guava's CancellationException in our own Exception
27d2240
@diegomarquezp
reset test and basic retry future
383b42d
@diegomarquezp
use logging to inform of failed LRO
a9245ba
@diegomarquezp
add license and comment to fake log handler
fa774a2
@diegomarquezp
diegomarquezp requested a review from a team November 10, 2023 20:19
@product-auto-label product-auto-label Bot added the size: m Pull request size is medium. label Nov 10, 2023
@diegomarquezp
format code
f245e1f
@diegomarquezp
diegomarquezp marked this pull request as draft November 10, 2023 20:22
diegomarquezp added 2 commits November 10, 2023 20:30
@diegomarquezp
fix license
f4fd1c0
@diegomarquezp
format souce
a899a89
@diegomarquezp diegomarquezp added the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 13, 2023
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 13, 2023
@diegomarquezp
diegomarquezp marked this pull request as ready for review November 13, 2023 16:35
lqiu96
lqiu96 reviewed Nov 13, 2023
View reviewed changes
Comment thread gax-java/gax/src/main/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithm.java Outdated
if (super.shouldRetry(nextAttemptSettings)) {
return true;
}
if (LOGGER.isLoggable(Level.SEVERE)) {

@lqiu96 lqiu96 Nov 13, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

QQ, is there a reason SEVERE logging level was picked? It seems like that is meant for more fatal application issues (and less for an RPC timeout), but I also am not sure if there is a better level (Info? Warning?).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That makes sense. My reasoning was more like "exception=severe", but in the context of a timeout on a request I agree something like WARNING is better

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I decreased it to WARNING

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
diegomarquezp added 2 commits November 13, 2023 16:50
@diegomarquezp
decrease LRO timeout logging level to WARNING
e28c03f
@diegomarquezp
fix logging threshold check
2328c01
@diegomarquezp
diegomarquezp requested a review from lqiu96 November 13, 2023 17:02
lqiu96
lqiu96 reviewed Nov 13, 2023
View reviewed changes
Comment thread gax-java/gax/src/main/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithm.java
*/
public class OperationTimedPollAlgorithm extends ExponentialRetryAlgorithm {

@VisibleForTesting

@lqiu96 lqiu96 Nov 13, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: I don't think the logger needs a VisibleForTesting annotation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
lqiu96
lqiu96 reviewed Nov 13, 2023
View reviewed changes
Comment thread ...case/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java Outdated
@Test
public void testGRPC_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExceededException()
throws Exception {
FakeLogHandler logHandler = new FakeLogHandler();

@lqiu96 lqiu96 Nov 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: Might be better to create field for FakeLogHandler that all tests can use without having to initialize in multiple tests, if possible

setUp() -> Creates it
clean() -> clears all the message so the next test can run

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Makes sense, thanks! I only added a setUp() since creating a new handler wipes out the old handler with its maessages

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lqiu96
lqiu96 reviewed Nov 13, 2023
View reviewed changes
Comment thread ...case/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java Outdated
Comment on lines +171 to +172
FakeLogHandler logHandler = new FakeLogHandler();
OperationTimedPollAlgorithm.LOGGER.addHandler(logHandler);

@lqiu96 lqiu96 Nov 13, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
lqiu96
lqiu96 approved these changes Nov 13, 2023
View reviewed changes

@lqiu96 lqiu96 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, added a few nits. Can you also have @burkedavison or @JoeWang1127 take a quick look? Thanks for this @diegomarquezp

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@diegomarquezp
use common log handler setup for ITLongRunningOperation
7f0a751
JoeWang1127
JoeWang1127 reviewed Nov 13, 2023
View reviewed changes
Comment thread gax-java/gax/src/main/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithm.java Outdated
*/
public class OperationTimedPollAlgorithm extends ExponentialRetryAlgorithm {

public static Logger LOGGER = Logger.getLogger(OperationTimedPollAlgorithm.class.getName());

@JoeWang1127 JoeWang1127 Nov 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why the logger has to be public?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is so it can be accessed by the test in order to add a log handler. @lqiu96, maybe we can fall back to @VisibleForTesting because it is... visible only for testing?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lqiu96 lqiu96 Nov 13, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ah, right. Let's try the the default package scope, which I believe should still be accessible. If not, then we can add the annotation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JoeWang1127 JoeWang1127 Nov 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There're some suggestions made by Quality Gate: https://sonarcloud.io/project/issues?id=googleapis_gapic-generator-java&pullRequest=2236&resolved=false&types=CODE_SMELL

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread ...case/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java Outdated
int attemptCount = operationFuture.getPollingFuture().getAttemptSettings().getAttemptCount();
assertThat(attemptCount).isGreaterThan(1);
assertEquals(1, logHandler.getAllMessages().size());
assertThat(logHandler.getAllMessages().get(0))

@JoeWang1127 JoeWang1127 Nov 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is there a guarantee that the message is the first element of the list?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

So far the implementation has only one case where the logger is used. I think the current assertions are a safe heuristic. Maybe I can assert that at least one message contains the entry I'm looking for?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JoeWang1127 JoeWang1127 Nov 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe I can assert that at least one message contains the entry I'm looking for?

I think this maybe better.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread gax-java/gax/src/test/java/com/google/api/gax/util/FakeLogHandler.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JoeWang1127

JoeWang1127 commented Nov 13, 2023

Copy link
Copy Markdown
Contributor

I don't have a lot of context of this change so I provide some general suggestions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@diegomarquezp
fix license header year
e603ba7
@diegomarquezp
format source
b8ad027
burkedavison
burkedavison reviewed Nov 13, 2023
View reviewed changes
Comment thread ...case/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java
@@ -39,6 +43,13 @@
*/
public class ITLongRunningOperation {

@burkedavison burkedavison Nov 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Are we sure that this already-complex integration test the best place to add these new assertions? Rephrased: Is the showcase server needed to verify the client's logging behavior?

The changes we're making are in com.google.api.gax.longrunning.OperationTimedPollAlgorithm, but we don't yet have any unit tests for this class. Is it possible for us to write a direct unit test that focuses purely on the logging behavior of OperationTimedPollAlgorithm.shouldRetry()?

Without looking at this PR and only the logic we're trying to test, I would have expected to see a set of unit tests that were roughly:

// WARNING: This is all completely pseudocode...
public void testTroubleshootingLinkProvided() {
  LOGGER.addHandler(handler);
  assertThrows(..., algorithm.shouldRetry(NEXT_ATTEMPT_SHOULD_NOT_RETRY));
  assertThat(handler.getLogMessage().exists())
  assertThat(handler.getLogMessage().contains(LRO_TROUBLESHOOTING_LINK));
}
public void testTroubleshootingLinkNotProvided() {
  LOGGER.addHandler(handler);
  assertThat(algorithm.shouldRetry(NEXT_ATTEMPT_SHOULD_RETRY), is(true));
  assertThat(handler.getLogMessage().doesNotExist())
}

Then the integration test can be kept clear of client-side-only implementation details, allowing the person debugging a problem to focus only on the relevant interactions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@burkedavison thank you. At some point writing the test in this file helped me find that the exception thrown in OperationTimedPollAlgorithm does not bubble up to the client (hence the use of a logger), but maybe that's just part of finding out about the behavior of LROs. I will move the test case to a unit test in gax

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
diegomarquezp added 3 commits November 13, 2023 22:40
@diegomarquezp
reset lro it
8f60925
@diegomarquezp
change to unit tests
0e53559
@diegomarquezp
reset testjar exports
2c33515
burkedavison
burkedavison approved these changes Nov 14, 2023
View reviewed changes
Comment thread gax-java/gax/src/test/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithmTest.java Outdated
Comment on lines +103 to +114
FakeApiClock clock = new FakeApiClock(System.nanoTime());
OperationTimedPollAlgorithm algorithm =
OperationTimedPollAlgorithm.create(FAST_RETRY_SETTINGS, clock);
TimedAttemptSettings settings =
TimedAttemptSettings.newBuilder()
.setGlobalSettings(FAST_RETRY_SETTINGS)
.setRetryDelay(Duration.ofMillis(1l))
.setRpcTimeout(Duration.ofMillis(1l))
.setRandomizedRetryDelay(Duration.ofMillis(1l))
.setAttemptCount(0)
.setFirstAttemptStartTimeNanos(clock.nanoTime())
.build();

@burkedavison burkedavison Nov 14, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you for the improvement by moving this to a unit test!

At this point, I'm just nit-picking: you could choose to extract all three of these variables to class fields, and further reduce both of these tests to their essential checks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@diegomarquezp diegomarquezp Nov 14, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

added

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gax-java/gax/src/test/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithmTest.java Outdated
.setAttemptCount(0)
.setFirstAttemptStartTimeNanos(clock.nanoTime())
.build();
clock.incrementNanoTime(1 * 1000 * 1000 * 1000);

@burkedavison burkedavison Nov 14, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Consider a quick comment here to clarify what part of the logic this is triggering to force a no-retry.
For example (if this is accurate):

clock.incrementNanoTime(1 * 1000 * 1000 * 1000); // Force Rpc Timeout

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegomarquezp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@diegomarquezp diegomarquezp Nov 14, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

good point. I added this comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@diegomarquezp
simplify unit test
152fc5b
burkedavison
burkedavison reviewed Nov 14, 2023
View reviewed changes
Comment thread gax-java/gax/src/test/java/com/google/api/gax/longrunning/OperationTimedPollAlgorithmTest.java Outdated
Comment on lines +60 to +61
private static TimedAttemptSettings timedAttemptSettings;
private static FakeApiClock clock;

@burkedavison burkedavison Nov 14, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

By making these static and initializing them in an instance method (@Before), the test now becomes flaky if multithreading is ever enabled. One test may overwrite the reference during a different test.

Suggested change
private static TimedAttemptSettings timedAttemptSettings;
private static FakeApiClock clock;
private TimedAttemptSettings timedAttemptSettings;
private FakeApiClock clock;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegomarquezp diegomarquezp Nov 14, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ah, good catch. thanks. I didn't think through the need for static in this test class. I just switched them as instance variables

edit: I didn't notice this comment had a suggestion but I added the same change in another commit

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@diegomarquezp
use instance variables in test
81a978c
@sonarqubecloud

sonarqubecloud Bot commented Nov 14, 2023

Copy link
Copy Markdown

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

80.0% 80.0% Coverage
0.0% 0.0% Duplication

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sonarqubecloud

sonarqubecloud Bot commented Nov 14, 2023

Copy link
Copy Markdown

[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

80.0% 80.0% Coverage
0.0% 0.0% Duplication

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@diegomarquezp
diegomarquezp merged commit 741e40c into main Nov 14, 2023
@diegomarquezp
diegomarquezp deleted the longrunning-error-message-2 branch November 14, 2023 17:00
@release-please release-please Bot mentioned this pull request Nov 13, 2023
chore(main): release 2.30.0 #2228
Merged
@blakeli0 blakeli0 mentioned this pull request Jul 29, 2025
fix: improve error messaging for LRO CancellationException #3873
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@lqiu96 lqiu96 lqiu96 approved these changes
@burkedavison burkedavison burkedavison approved these changes
@JoeWang1127 JoeWang1127 JoeWang1127 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size: m Pull request size is medium.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Improve LRO's Error Message on Timeout

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@diegomarquezp @JoeWang1127 @lqiu96 @burkedavison
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.