{"record":{"id":"bf1d23ae72a2898d","repo":"RicoSuter/NSwag","slug":"process-startinfo-filename-timed-out","errorCode":null,"errorMessage":"Process {startInfo.FileName} timed out.","messagePattern":"Process (.+?) timed out\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/Commands/Generation/AspNetCore/Exe.cs","lineNumber":64,"sourceCode":"#pragma warning disable CA2201\n                    tcs.TrySetException(new Exception($\"Process failed with non-zero exit code '{process.ExitCode}'.\"));\n#pragma warning restore CA2201\n                }\n            };\n\n            if (console != null)\n            {\n                process.OutputDataReceived += (_, eventArgs) => console.WriteMessage(eventArgs.Data + Environment.NewLine);\n                process.ErrorDataReceived += (_, eventArgs) => console.WriteError(eventArgs.Data + Environment.NewLine);\n\n                process.BeginErrorReadLine();\n                process.BeginOutputReadLine();\n            }\n\n            var result = await Task.WhenAny(tcs.Task, Task.Delay(timeout ?? TimeSpan.FromSeconds(60 * 5))).ConfigureAwait(false);\n            if (result != tcs.Task)\n            {\n                throw new InvalidOperationException($\"Process {startInfo.FileName} timed out.\");\n            }\n            else\n            {\n                console?.WriteMessage($\"Done executing command. Exit Code: {process.ExitCode}.{Environment.NewLine}\");\n                return process.ExitCode;\n            }\n        }\n\n        private static string ToArguments(IReadOnlyList<string> args)\n        {\n            var builder = new StringBuilder();\n            for (var i = 0; i < args.Count; i++)\n            {\n                var argument = args[i];\n                if (i != 0)\n                {\n                    builder.Append(' ');\n                }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/Commands/Generation/AspNetCore/Exe.cs#L46-L82","documentation":"Exe.RunAsync starts a child process and waits for it to exit, racing it against a timeout (default 5 minutes when no explicit timeout is passed). If the process does not exit in time, the awaited delay wins and this error is thrown, indicating the generation (or metadata) process hung.","triggerScenarios":"Calling Exe.RunAsync (used for both `dotnet msbuild` metadata queries and the launcher process) where the process stays alive past `timeout ?? TimeSpan.FromSeconds(60 * 5)` — e.g. the ASP.NET app starts its web host and never terminates.","commonSituations":"The target app's Program.cs starts the Kestrel host and blocks instead of exiting after generation; a long build over the 5-minute default on slow CI machines; deadlock in app startup waiting on a database/network; app prompting for input on stdin.","solutions":["Ensure the ASP.NET Core app terminates after generation: use the NSwag-provided host builder pattern (CreateBuilder for generation) rather than unconditionally running the web host.","Increase the timeout by invoking Exe.RunAsync with a larger TimeSpan if builds/starts are legitimately slow.","Check for blocking startup code (sync DB calls, service discovery) and remove or shorten it.","Guard any `app.Run()` call so it is skipped when running under the NSwag launcher/environment."],"exampleFix":"// before (Program.cs)\nvar app = builder.Build();\napp.Run(); // blocks forever during swagger generation\n// after\nif (Environment.GetEnvironmentVariable(\"ASPNETCORE_ENVIRONMENT\") != \"Generation\")\n{\n    app.Run();\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await Exe.RunAsync(exe, args, host, timeout: TimeSpan.FromMinutes(15));\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"timed out\"))\n{\n    // log child output, kill orphaned process, optionally retry with a larger timeout\n}","preventionTips":["Make sure the generated app exits after spec generation (guard app.Run()).","Pass an explicit generous timeout in slow CI environments.","Remove interactive/console-input prompts from startup code.","Fix blocking startup dependencies (DB, network) with timeouts of their own."],"tags":["timeout","process","hang"],"backgroundTag":"request-timeout","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}