You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(membase): bound a graph query's total time, let the caller cancel it, and stop retrying timeouts - #1508
MembaseGraphDb.ExecuteQueryAsync retries transient failures (502/503/504 and non-query 500s) three times with 2 s, 4 s and 8 s back-off. When Membase keeps returning 500, one query stays busy for 14 s of back-off alone. A caller that waits with its own deadline has given up long before, and the retries keep hitting Membase while it is already failing. A caller also had no way to stop a query whose result it no longer needs.
The per-attempt timeout (TimeoutSecond / 3) never fired. Polly timeouts are optimistic and only cancel through the CancellationToken passed to the delegate, but IMembaseApi.CypherQueryAsync took no token. A hanging call therefore ran until the 90 s HttpClient timeout.
Change
IMembaseApi.CypherQueryAsync takes a CancellationToken, and the policy passes its token through, so timeouts and cancellation now reach the HTTP call.
One timeout covers the whole query, back-off included. It is GraphQueryExecuteOptions.Timeout (new, optional) when the caller sets it, and Membase:TimeoutSecond otherwise.
The per-attempt timeout is removed, and timeouts are no longer retried. Once it actually fired, a healthy query slower than TimeoutSecond / 3 was cut, retried and timed out every time: about 54 s and a failure, instead of a slower success. A query that runs out of time is usually just slow, so another attempt does not help. Only transient HTTP failures are retried.
GraphQueryExecuteOptions.CancellationToken (new, [JsonIgnore]) lets the caller cancel the query, retries included. A typical use is passing HttpContext.RequestAborted. A caller's cancellation is not treated as a Membase error:
It is logged at Information level, without the query text.
It surfaces as OperationCanceledException, even when the HTTP client wraps the cancellation in its own exception.
MembaseController.ExecuteGraphQuery takes a CancellationToken action parameter (bound by MVC to RequestAborted) and passes it on, so an aborted /membase/{graphId}/query request stops its query.
The Refit client timeout is Math.Max(90 s, TimeoutSecond) instead of a fixed 90 s, so a larger TimeoutSecond is not cut at 90 s. The 90 s floor stays for calls made on IMembaseApi directly, which have no other timeout.
With the default TimeoutSecond = 30
Before
After
Healthy query that takes 12 s
succeeds at 12 s
succeeds at 12 s
Call that hangs
fails at 90 s (HttpClient)
fails at 30 s
Consecutive 500s
fails after ~14 s, 3 retries
same, within 30 s
Caller sets Timeout = 5 s
(no such option)
fails at 5 s
Caller cancels
(not possible)
stops at once, no retry
Behaviour change to note
A healthy query that takes between TimeoutSecond and 90 s used to succeed and now times out. Raise Membase:TimeoutSecond if a deployment runs queries that slow.
Testing
Tests live in the downstream app that consumes this plugin. They use a mocked IMembaseApi and check six cases:
Consecutive 500s fail within a 1 s budget, after a single call.
A hanging call with a 0.5 s budget sees its token cancelled.
With no budget and TimeoutSecond = 1, a hanging call fails in about 1 s, with no retry.
With TimeoutSecond = 3, a 1.5 s query succeeds on its first attempt.
A caller cancellation stops the query at once, with no retry.
A caller cancellation that the HTTP client wraps still surfaces as OperationCanceledException.
The full downstream suite passes against this branch.
…ncluded
ExecuteQueryAsync retried transient failures with 2/4/8 s back-off, so a Membase
outage kept each query busy for well over its callers' own deadlines. The
per-attempt timeout never fired either: Polly timeouts are optimistic and need a
cancellation token, but CypherQueryAsync took none, so a hanging call ran to the
90 s HttpClient timeout.
- GraphQueryExecuteOptions.Timeout: optional upper bound for the whole query,
applied as the outermost policy so it also cuts the back-off short. Null keeps
today's behaviour.
- IMembaseApi.CypherQueryAsync takes a CancellationToken, and the retry policy
passes its token through, so both timeouts now cancel the HTTP call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rying timeouts
The per-attempt timeout (TimeoutSecond / 3) started firing once the previous
commit passed the token through. A healthy query slower than that limit was then
cut and retried, timed out the same way each time, and failed after ~54 s
instead of succeeding.
A query that times out is usually just slow, so retrying it does not help. Now
one timeout covers the whole query, back-off included: the caller's
GraphQueryExecuteOptions.Timeout, or Membase:TimeoutSecond when none is given.
Only transient HTTP failures are retried.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yuyixg
changed the title
fix(membase): let callers bound a graph query's total time, retries included
fix(membase): bound a graph query's total time, and stop retrying timeouts
Nov 20, 2026
GraphQueryExecuteOptions.CancellationToken (JSON-ignored) cancels the query,
retries and back-off included, e.g. when the request that needs the result is
aborted. MembaseGraphDb hands it to the retry policy, so it reaches the HTTP
call.
A caller's cancellation is not a Membase error: it is logged at information
level without the query text, and surfaced as OperationCanceledException even
when the HTTP client wraps it in its own exception.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yuyixg
changed the title
fix(membase): bound a graph query's total time, and stop retrying timeouts
fix(membase): bound a graph query's total time, let the caller cancel it, and stop retrying timeouts
Nov 20, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two moderate issues remain: request cancellation is not propagated through the public query endpoint, and the hard-coded 90-second Refit timeout can override configured or caller-supplied longer budgets.
This PR makes Membase graph queries cancellable and bounds their total execution time, including retry backoff, while preventing timeout-triggered retries.
Changes:
Adds cancellation-token support to the Membase API and propagates it through Polly to Refit.
Replaces per-attempt timeouts with one configurable whole-query timeout.
Restricts retries to transient HTTP failures and normalizes caller cancellation as OperationCanceledException.
…nd exceed 90 s
- MembaseController.ExecuteGraphQuery passes HttpContext.RequestAborted, so an
aborted /membase/{graphId}/query request stops its query and retries.
- The Refit client timeout was a fixed 90 s, which cut any longer
Membase:TimeoutSecond short. It is now the larger of 90 s and TimeoutSecond.
The 90 s floor stays because calls made on IMembaseApi directly have no other
timeout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues were identified, and the changes consistently propagate cancellation while enforcing a bounded whole-query timeout and preserving appropriate transient-failure retries.
…n parameter
MVC binds a CancellationToken action parameter to HttpContext.RequestAborted,
and a direct call without an HTTP context gets CancellationToken.None instead of
a null HttpContext.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The token is now propagated into MembaseGraphDb, but this action still catches the resulting OperationCanceledException in the broad handler below and converts caller/request cancellation into a 500 ErrorResult. That treats a disconnected /membase/{graphId}/query request as a server error (and prevents cancellation from surfacing to in-process callers of the action); rethrow cancellation when cancellationToken.IsCancellationRequested before handling actual failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Problem
MembaseGraphDb.ExecuteQueryAsyncretries transient failures (502/503/504 and non-query 500s) three times with 2 s, 4 s and 8 s back-off. When Membase keeps returning 500, one query stays busy for 14 s of back-off alone. A caller that waits with its own deadline has given up long before, and the retries keep hitting Membase while it is already failing. A caller also had no way to stop a query whose result it no longer needs.The per-attempt timeout (
TimeoutSecond / 3) never fired. Polly timeouts are optimistic and only cancel through theCancellationTokenpassed to the delegate, butIMembaseApi.CypherQueryAsynctook no token. A hanging call therefore ran until the 90 sHttpClienttimeout.Change
IMembaseApi.CypherQueryAsynctakes aCancellationToken, and the policy passes its token through, so timeouts and cancellation now reach the HTTP call.GraphQueryExecuteOptions.Timeout(new, optional) when the caller sets it, andMembase:TimeoutSecondotherwise.TimeoutSecond / 3was cut, retried and timed out every time: about 54 s and a failure, instead of a slower success. A query that runs out of time is usually just slow, so another attempt does not help. Only transient HTTP failures are retried.GraphQueryExecuteOptions.CancellationToken(new,[JsonIgnore]) lets the caller cancel the query, retries included. A typical use is passingHttpContext.RequestAborted. A caller's cancellation is not treated as a Membase error:OperationCanceledException, even when the HTTP client wraps the cancellation in its own exception.MembaseController.ExecuteGraphQuerytakes aCancellationTokenaction parameter (bound by MVC toRequestAborted) and passes it on, so an aborted/membase/{graphId}/queryrequest stops its query.Math.Max(90 s, TimeoutSecond)instead of a fixed 90 s, so a largerTimeoutSecondis not cut at 90 s. The 90 s floor stays for calls made onIMembaseApidirectly, which have no other timeout.TimeoutSecond = 30Timeout = 5 sBehaviour change to note
A healthy query that takes between
TimeoutSecondand 90 s used to succeed and now times out. RaiseMembase:TimeoutSecondif a deployment runs queries that slow.Testing
Tests live in the downstream app that consumes this plugin. They use a mocked
IMembaseApiand check six cases:TimeoutSecond = 1, a hanging call fails in about 1 s, with no retry.TimeoutSecond = 3, a 1.5 s query succeeds on its first attempt.OperationCanceledException.The full downstream suite passes against this branch.
🤖 Generated with Claude Code