Operation Elapsed property is not calculated properly for completed operations with retriable response status

Description

I reproduced the issue on the scenario with an error VBucketBelongsToAnotherServer so let’s look at it as an example.

Note: it is important to be able to simulate an operation that completes w/t exceptions, but retriable status code and to retry the operation until timeout.

When this kind of response is received, SDK calls HandleOperationCompleted and this method regardless of the branch always calls StopRecording method which actually stops internal Stopwatch object that an operation uses to track how much time the operation took to be completed.

Assuming that no exceptions are thrown in the above try block we see that eventually it calls:

Which completes the task, so that [the rest of the ClusterNode.ExecuteOp code|https://github.com/couchbase/couchbase-net-client/blob/91b3674ab2c40f760c1ec75092f89c85b18ec9f2/src/Couchbase/Core/ClusterNode.cs#L555-L559] might be executed

Since it’s not a transport failure or something similar the ExecuteOp method is successfully completed with the response status as a return value. 

Going up the stack we reach RetryOrchestrator.RetryAsync method which checks if the status is retriable. In our case it is retriable which means that the operation will be attempted to execute again. Thus the operation will be retried until the cancellation token provided is not cancelled by timeout.

After timeout the execution goes to the catch block in the RetryAsync method. And there is the following code:

And as we know when the operation was completed on the first time, its stopwatch was stopped, so {{Elapsed }}represents only the first attempt of the operation, so this code will throw TaskCancelledException, but in fact should throw TimeoutException.

Environment

None

Gerrit Reviews

None

Release Notes Description

None

Attachments

1

Activity

Show:

Jeffry Morris May 11, 2023 at 6:50 PM

Can you try this patch and give feedback on it?

Thanks,
Jeff

Eugene Shcherbo May 2, 2023 at 9:31 AM

Seems like I don't have permissions to edit the ticket, but the link the rest of the ClusterNode.ExecuteOp code in the description points to a wrong place. The correct link is : https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchbase/Core/ClusterNode.cs#L558-L601

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Story Points

Fix versions

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created May 2, 2023 at 9:29 AM
Updated May 15, 2023 at 6:11 PM
Resolved May 12, 2023 at 9:08 PM
Instabug