From 3361fa6fac9fd4ba90c60ea0f5398abac3a82ac3 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Fri, 9 Aug 2024 04:47:26 -0700 Subject: [PATCH] CBG-4067 Only skip releasing sequences for timeouts (#7050) We want to release sequences in scenarios where we know the write did not occur. --- base/error.go | 12 ++++++++++++ db/crud.go | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/base/error.go b/base/error.go index cddf0a72fa..f77a62eb91 100644 --- a/base/error.go +++ b/base/error.go @@ -257,6 +257,18 @@ func IsTemporaryKvError(err error) bool { return false } +func IsTimeoutError(err error) bool { + if err == nil { + return false + } + + if errors.Is(err, gocb.ErrTimeout) || errors.Is(err, ErrTimeout) { + return true + } + + return false +} + func IsXattrNotFoundError(err error) bool { if unwrappedErr := pkgerrors.Cause(err); unwrappedErr == nil { return false diff --git a/db/crud.go b/db/crud.go index 2cc5c8ce1d..b495b12a1d 100644 --- a/db/crud.go +++ b/db/crud.go @@ -2096,7 +2096,8 @@ func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, do // If the WriteUpdate didn't succeed, check whether there are unused, allocated sequences that need to be accounted for if err != nil { - if !base.IsTemporaryKvError(err) { + // For timeout errors, the write may or may not have succeeded so we cannot release the sequence as unused + if !base.IsTimeoutError(err) { if docSequence > 0 { if seqErr := db.sequences().releaseSequence(ctx, docSequence); seqErr != nil { base.WarnfCtx(ctx, "Error returned when releasing sequence %d. Falling back to skipped sequence handling. Error:%v", docSequence, seqErr)