Skip to content

Better way for setting operation timeout and retries in Firestore SDK #11322

@alex-namely

Description

@alex-namely

Hello,

I'm looking for a convenient way of setting timeouts and optionally retries for basic Firestore operations.

As an example, I have a read document operation that in some weird cases may be running for more than a minute:

firestoreDb.Collection(collectionName).Document(key).GetSnapshotAsync()

I am aware that there is a way to provide a cancellation token to some of methods but in my opinion, it is not a clean way to set timeout moreover using CreateLinkedTokenSource adds additional overhead and requires advanced technics (like pooling and disposing) to be used.

Naive example:

 var timeoutCts = new CancellationTokenSource();
 timeoutCts.CancelAfter(timeSpan);
 var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken);
 return combinedCts.Token;

I can be wrong but I'm under impression that in .NET SDK timeouts and retries were hard-coded.
https://github.com/googleapis/google-cloud-dotnet/blob/main/apis/Google.Cloud.Firestore/Google.Cloud.Firestore/FirestoreDb.cs#L78-L86

As a suggestion I would like to highlight Python SDK where setting timeouts and retries requires no effort.

https://cloud.google.com/python/docs/reference/firestore/latest/query

retry ([google.api_core.retry.Retry](https://googleapis.dev/python/google-api-core/latest/retry.html#google.api_core.retry.Retry)) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout ([float](https://python.readthedocs.io/en/latest/library/functions.html#float)) – The timeout for this request. Defaults to a system-specified value.

JFYI: There was an old issue #2471 but I think it is different.

Metadata

Metadata

Assignees

Labels

type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions