{"record":{"id":"66d27a4d555ac29e","repo":"microsoft/garnet","slug":"can-spin-wait-for-commit-checkpoint-completion-o","errorCode":null,"errorMessage":"Can spin-wait for commit (checkpoint completion) only if wait is true","messagePattern":"Can spin-wait for commit \\(checkpoint completion\\) only if wait is true","errorType":"exception","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/ClientSession/ClientSession.cs","lineNumber":297,"sourceCode":"            try\n            {\n                return UnsafeCompletePending(sessionFunctions, getOutputs, wait, spinWaitForCommit);\n            }\n            finally\n            {\n                UnsafeSuspendThread();\n            }\n        }\n\n        internal bool UnsafeCompletePending<TSessionFunctionsWrapper>(TSessionFunctionsWrapper sessionFunctions, bool getOutputs, bool wait, bool spinWaitForCommit)\n            where TSessionFunctionsWrapper : ISessionFunctionsWrapper<TInput, TOutput, TContext, TStoreFunctions, TAllocator>\n        {\n            var requestedOutputs = getOutputs ? completedOutputs : default;\n            var result = store.InternalCompletePending(sessionFunctions, wait, requestedOutputs);\n            if (spinWaitForCommit)\n            {\n                if (!wait)\n                    throw new TsavoriteException(\"Can spin-wait for commit (checkpoint completion) only if wait is true\");\n                do\n                {\n                    _ = store.InternalCompletePending(sessionFunctions, wait, requestedOutputs);\n                    if (store.InRestPhase())\n                    {\n                        _ = store.InternalCompletePending(sessionFunctions, wait, requestedOutputs);\n                        return true;\n                    }\n                } while (wait);\n            }\n            return result;\n        }\n\n        /// <inheritdoc/>\n        internal ValueTask CompletePendingAsync<TSessionFunctionsWrapper>(TSessionFunctionsWrapper sessionFunctions, bool waitForCommit = false, CancellationToken token = default)\n            where TSessionFunctionsWrapper : ISessionFunctionsWrapper<TInput, TOutput, TContext, TStoreFunctions, TAllocator>\n            => CompletePendingAsync(sessionFunctions, getOutputs: false, waitForCommit, token);\n","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/ClientSession/ClientSession.cs#L279-L315","documentation":"UnsafeCompletePending accepts both a 'wait' flag and a 'spinWaitForCommit' flag. spinWaitForCommit=true means the caller wants to block-spin until the store enters its REST phase (checkpoint completion). This only makes sense if wait is also true — spin-waiting without waiting is contradictory and indicates a logic error. The throw catches this contradictory parameter combination early.","triggerScenarios":"Calling UnsafeCompletePending (or a higher-level API that forwards these flags) with spinWaitForCommit=true and wait=false.","commonSituations":"Passing spinWaitForCommit through from user options without also setting wait=true; code that defaults wait=false but conditionally enables spin-wait-for-commit.","solutions":["When spinWaitForCommit is true, always pass wait=true.","If you truly want non-blocking completion, set spinWaitForCommit=false.","Validate the flag combination before calling: if (spinWaitForCommit && !wait) throw or correct the flags."],"exampleFix":"// before\nsession.UnsafeCompletePending(funcs, getOutputs: true, wait: false, spinWaitForCommit: true);\n\n// after\nsession.UnsafeCompletePending(funcs, getOutputs: true, wait: true, spinWaitForCommit: true);","handlingStrategy":"validation","validationCode":"if (spinWaitForCommit && !wait) throw new ArgumentException(\"spinWaitForCommit requires wait=true.\", nameof(spinWaitForCommit));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When requesting spin-wait-for-commit, always set wait=true.","Validate the (wait, spinWaitForCommit) combination at the call site.","Default spinWaitForCommit to false unless explicitly needed."],"tags":["tsavorite","session","pending-ops","checkpoint","parameter-validation","csharp"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}