{"record":{"id":"18ce2cb6d23aee47","repo":"microsoft/FASTER","slug":"make-sure-all-async-operations-issued-on-this-session-are","errorCode":null,"errorMessage":"Make sure all async operations issued on this session are awaited and completed first","messagePattern":"Make sure all async operations issued on this session are awaited and completed first","errorType":"exception","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/ClientSession/ClientSession.cs","lineNumber":965,"sourceCode":"                status = fht.InternalModifiedBitOperation(ref key, out modifiedInfo, false);\n            while (fht.HandleImmediateNonPendingRetryStatus<Input, Output, Context, InternalFasterSession>(status, FasterSession));\n            return modifiedInfo.Modified;\n        }\n\n        /// <inheritdoc/>\n        internal unsafe bool IsModified(Key key) => IsModified(ref key);\n\n        /// <summary>\n        /// Wait for commit of all operations completed until the current point in session.\n        /// Does not itself issue checkpoint/commits.\n        /// </summary>\n        /// <returns></returns>\n        public async ValueTask WaitForCommitAsync(CancellationToken token = default)\n        {\n            token.ThrowIfCancellationRequested();\n\n            if (!ctx.prevCtx.pendingReads.IsEmpty || !ctx.pendingReads.IsEmpty)\n                throw new FasterException(\"Make sure all async operations issued on this session are awaited and completed first\");\n\n            // Complete all pending sync operations on session\n            await CompletePendingAsync(token: token).ConfigureAwait(false);\n\n            var task = fht.CheckpointTask;\n            CommitPoint localCommitPoint = LatestCommitPoint;\n            if (localCommitPoint.UntilSerialNo >= ctx.serialNum && localCommitPoint.ExcludedSerialNos?.Count == 0)\n                return;\n\n            while (true)\n            {\n                await task.WithCancellationAsync(token).ConfigureAwait(false);\n                Refresh();\n\n                task = fht.CheckpointTask;\n                localCommitPoint = LatestCommitPoint;\n                if (localCommitPoint.UntilSerialNo >= ctx.serialNum && localCommitPoint.ExcludedSerialNos?.Count == 0)\n                    break;","sourceCodeStart":947,"sourceCodeEnd":983,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/ClientSession/ClientSession.cs#L947-L983","documentation":"WaitForCommitAsync waits for an ongoing checkpoint to become durable, but the session's execution contexts still hold uncompleted pending reads. FASTER throws FasterException to avoid waiting for a commit while async reads issued on the session have not been awaited/completed.","triggerScenarios":"Calling session.WaitForCommitAsync() while ctx.pendingReads or ctx.prevCtx.pendingReads is non-empty — i.e. async Read operations were issued (returned a ValueTask that was not awaited or CompletePendingAsync not yet run for them).","commonSituations":"Fire-and-forget async reads (not awaiting the returned ValueTask) followed by WaitForCommitAsync before checkpoint; forgetting to CompletePendingAsync between reads and commit wait.","solutions":["Await every async Read's returned ValueTask (var (status, output) = await task;) before WaitForCommitAsync.","Call await session.CompletePendingAsync() (or CompletePendingAsync(waitForCommit: true) directly) before WaitForCommitAsync.","Use CompletePendingAsync(waitForCommit: true) to combine completion and commit waiting in one call."],"exampleFix":"// before\nsession.ReadAsync(input, key, ctx); // not awaited\nawait session.WaitForCommitAsync(); // throws\n\n// after\nvar result = await session.ReadAsync(input, key, ctx);\nawait session.WaitForCommitAsync();","handlingStrategy":"validation","validationCode":"// ensure no un-awaited async reads remain\nawait session.CompletePendingAsync(); // completes and drains pendingReads\nawait session.WaitForCommitAsync();","typeGuard":null,"tryCatchPattern":"try\n{\n    await session.WaitForCommitAsync();\n}\ncatch (FasterException ex) when (ex.Message.Contains(\"async operations\"))\n{\n    await session.CompletePendingAsync(waitForCommit: true);\n}","preventionTips":["Always await ReadAsync/RMWAsync ValueTasks; never fire-and-forget them.","Prefer CompletePendingAsync(waitForCommit: true) over separate completion + WaitForCommitAsync.","Enable analyzers/treat warnings to catch un-awaited tasks (CS4014-style patterns)."],"tags":["csharp","faster","async","checkpoint","pending-operations"],"backgroundTag":"invalid-state-transition","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}