{"record":{"id":"9c2aa4c1b4e002b6","repo":"Cysharp/UniTask","slug":"already-continuation-registered-can-not-await-twi","errorCode":null,"errorMessage":"Already continuation registered, can not await twice or get Status after await.","messagePattern":"Already continuation registered, can not await twice or get Status after await\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs","lineNumber":291,"sourceCode":"                C.1: win OnCompleted -> TrySet invoke saved continuation\n                C.2: win TrySet -> should invoke continuation here.\n            */\n\n            // not set continuation yet.\n            object oldContinuation = this.continuation;\n            if (oldContinuation == null)\n            {\n                continuationState = state;\n                oldContinuation = Interlocked.CompareExchange(ref this.continuation, continuation, null);\n            }\n\n            if (oldContinuation != null)\n            {\n                // already running continuation in TrySet.\n                // It will cause call OnCompleted multiple time, invalid.\n                if (!ReferenceEquals(oldContinuation, UniTaskCompletionSourceCoreShared.s_sentinel))\n                {\n                    throw new InvalidOperationException(\"Already continuation registered, can not await twice or get Status after await.\");\n                }\n\n                continuation(state);\n            }\n        }\n\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        private void ValidateToken(short token)\n        {\n            if (token != version)\n            {\n                throw new InvalidOperationException(\"Token version is not matched, can not await twice or get Status after await.\");\n            }\n        }\n    }\n\n    internal static class UniTaskCompletionSourceCoreShared // separated out of generic to avoid unnecessary duplication","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs#L273-L309","documentation":"Thrown by UniTaskCompletionSourceCore<TResult>.OnCompleted when a continuation is already registered and it is not the internal sentinel. UniTask structs are single-await by design: awaiting the same UniTask twice, or calling GetStatus/OnCompleted after awaiting, is invalid because the underlying source may have been returned to a pool. The guard detects double-registration of continuations.","triggerScenarios":"Awaiting the same UniTask variable twice. Calling GetStatus after await on the same UniTask. Storing a UniTask in a field and awaiting it from multiple call sites. Pooling issues where a returned UniTaskCompletionSourceCore is reused while a stale continuation is still registered.","commonSituations":"Storing a UniTask and awaiting it in a loop or retry logic. Passing a UniTask to multiple consumers. Debugging code that inspects status after the task has already been awaited. Misusing pooled AutoResetUniTaskCompletionSource.","solutions":["Await each UniTask exactly once; create a new UniTask for repeated operations","If you need multiple consumers, use UniTaskCompletionSource and expose Task multiple times, or broadcast via IUniTaskAsyncEnumerable","Never call GetStatus or OnCompleted on a UniTask after it has been awaited","Avoid storing UniTask in long-lived fields; await it immediately or convert to a re-awaitable source"],"exampleFix":"// before\nvar task = DoSomethingAsync();\nawait task;\nawait task; // throws: already awaited\n\n// after\nawait DoSomethingAsync();\nawait DoSomethingAsync(); // create a new task each time","handlingStrategy":"validation","validationCode":"// UniTask is single-await; ensure you only await once\n// If you need multi-consumer, use UniTaskCompletionSource:\nvar ucs = UniTaskCompletionSource.Create();\nucs.TrySetResult();\n// ucs.Task can be awaited multiple times via separate UniTask instances","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never await the same UniTask variable twice","Do not call GetStatus or OnCompleted after awaiting","Do not store UniTask in long-lived fields; await immediately","Use UniTaskCompletionSource or IUniTaskAsyncEnumerable for multi-consumer scenarios"],"tags":["unitask","completion-source","await-violation","single-use","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}