-
Notifications
You must be signed in to change notification settings - Fork 104
Make ApiContext timeout relative to the start of each RPC #592
Make ApiContext timeout relative to the start of each RPC #592
Conversation
This partially addresses googleapis#561. Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561. This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
|
@vam-google @garrettjonesgoogle Please take look when you have a moment |
Codecov Report
@@ Coverage Diff @@
## master #592 +/- ##
============================================
+ Coverage 73.96% 75.01% +1.05%
- Complexity 906 933 +27
============================================
Files 176 176
Lines 4067 4074 +7
Branches 317 322 +5
============================================
+ Hits 3008 3056 +48
+ Misses 907 865 -42
- Partials 152 153 +1
Continue to review full report at Codecov.
|
| .setMaxRpcTimeout(Duration.ofHours(1)) | ||
| .build()) | ||
| .setIdleTimeout(Duration.ofSeconds(1)) | ||
| .setTimeoutCheckInterval(Duration.ofSeconds(1)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Added a pile of tests. This PR is complete. Please review and if it looks good, please merge |
|
|
||
| @Nullable | ||
| @Override | ||
| public Duration getTimeout() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| CallOptions newOptions = | ||
| oldOptions.withDeadlineAfter(rpcTimeout.toMillis(), TimeUnit.MILLISECONDS); | ||
| GrpcCallContext nextContext = withCallOptions(newOptions); | ||
| public GrpcCallContext withTimeout(@Nullable Duration rpcTimeout) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| Preconditions.checkNotNull(callOptions); | ||
|
|
||
| // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline | ||
| if (grpcContext.getTimeout() != null) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| private GrpcCallContext( | ||
| Channel channel, | ||
| CallOptions callOptions, | ||
| @Nullable Duration rpcTimeout, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@vam-google I've renamed references to rpcTimeout to timeout. PTAL |
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 with few comments. Please address them before pushing (no need to ask for another LGTM)
| @InternalExtensionOnly | ||
| public final class HttpJsonCallContext implements ApiCallContext { | ||
| private final HttpJsonChannel channel; | ||
| private final Duration rpcTimeout; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * <p>This timeout only applies to a single RPC call; if timeouts are configured, the overall time | ||
| * taken will be much higher. | ||
| * <p>This sets the maximum amount of time a single unary RPC attempt can take. If retries are |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…#592) This partially addresses googleapis#561. Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561. This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
…#592) This partially addresses googleapis#561. Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561. This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
This partially addresses #561.
Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls
ApiContext.setTimeout(Duration)their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in #561.This PR tries to fix the situation by consistently treating
ApiContext.setTimeout(Duration)as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from #561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.