{"record":{"id":"0a361fa76025e599","repo":"microsoft/aspire","slug":"flushing-this-pendingpromises-size-pending-promise-s","errorCode":null,"errorMessage":"Flushing ${this._pendingPromises.size} pending promise(s). Consider awaiting fluent calls to avoid implicit flushing.","messagePattern":"Flushing (.+?) pending promise\\(s\\)\\. Consider awaiting fluent calls to avoid implicit flushing\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/Aspire.Hosting.CodeGeneration.TypeScript/Resources/transport.mts","lineNumber":802,"sourceCode":"        // rejections will also be re-thrown by build(). We accept this tradeoff\n        // because the common case — an un-awaited chain fails silently — should\n        // fail loud. The uncommon case (catch an error from an un-awaited chain,\n        // then continue to build) can opt out with:\n        //   createBuilder({ throwOnPendingRejections: false })\n        promise.then(\n            () => this._pendingPromises.delete(promise),\n            (err) => {\n                this._pendingPromises.delete(promise);\n                if (this.throwOnPendingRejections) {\n                    this._rejectedErrors.add(err);\n                }\n            }\n        );\n    }\n\n    async flushPendingPromises(): Promise<void> {\n        if (this._pendingPromises.size > 0) {\n            console.warn(`Flushing ${this._pendingPromises.size} pending promise(s). Consider awaiting fluent calls to avoid implicit flushing.`);\n            // Snapshot the current set before awaiting. Promises tracked after\n            // flush starts (e.g. by .then() callbacks or the build PromiseImpl\n            // constructor) are excluded. This prevents deadlocks where a tracked\n            // promise depends on flush completing.\n            const pending = [...this._pendingPromises];\n            await Promise.allSettled(pending);\n        }\n        if (this._rejectedErrors.size > 0) {\n            const errors = [...this._rejectedErrors];\n            this._rejectedErrors.clear();\n            throw new AggregateError(errors, 'One or more unawaited fluent calls failed');\n        }\n    }\n\n    /**\n     * Register a callback to be called when the connection is lost\n     */\n    onDisconnect(callback: () => void): void {","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.TypeScript/Resources/transport.mts#L784-L820","documentation":"The TypeScript code-generation transport tracks Promises created by fluent builder calls that were not awaited. When an implicit flush point is reached while unawaited promises are still pending, flushPendingPromises awaits them (allSettled) and warns that the user should await fluent calls explicitly. It is a diagnostic warning about potentially unintended fire-and-forget execution order.","triggerScenarios":"Calling fluent generator methods (e.g. chained builder operations) without await, so their Promises accumulate in _pendingPromises, and then hitting a flush boundary (another awaited operation or completion) that forces flushPendingPromises to settle them.","commonSituations":"Omitting 'await' on a fluent call in generated TypeScript code; relying on implicit flushing at the end of a build; mixing awaited and unawaited calls leading to nondeterministic ordering warnings during codegen runs.","solutions":["Await each fluent builder call (or the final call of the chain) so promises resolve explicitly and the warning disappears.","If intentionally fire-and-forget, capture the promise and await it later at a defined point rather than relying on implicit flush.","Check that build/emit entry points await flushPendingPromises (or the build completion API) before process exit so no promises are dropped."],"exampleFix":"// before\nbuilder.addEndpoint(\"http\").withPort(8080);\n// after\nawait builder.addEndpoint(\"http\").withPort(8080);","handlingStrategy":"validation","validationCode":"// Ensure fluent chains are awaited at build time before flushing.\nif (typeof promise?.then !== 'function') throw new TypeError('Expected a thenable from fluent call');\nawait promise; // always await before starting another operation","typeGuard":"function isPromiseLike(v) { return v != null && typeof v.then === 'function'; }","tryCatchPattern":"process.on('warning', (w) => {\n  if (String(w.message).includes('pending promise(s)')) {\n    // audit code paths that skip await on fluent calls\n  }\n});","preventionTips":["Always await fluent builder calls, including the last call of a chain.","Enable lint rules (e.g. @typescript-eslint/no-floating-promises) to catch missing awaits.","Do not rely on implicit flushing for ordering; flush explicitly at defined points."],"tags":["typescript","async","promises","codegen"],"backgroundTag":"unawaited-promise","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}