{"record":{"id":"da234fe56bac7620","repo":"dotnet/runtime","slug":"coreclr-shutdown-2-failed-error-0x-08x","errorCode":null,"errorMessage":"coreclr_shutdown_2 failed - Error: 0x%08x\n","messagePattern":"coreclr_shutdown_2 failed - Error: 0x%08x\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/coreclr/hosts/corerun/corerun.cpp","lineNumber":689,"sourceCode":"    }\n#endif // TARGET_WASI\n    return final_exit_code;\n#endif // TARGET_BROWSER\n}\n\nextern \"C\" int corerun_shutdown(int exit_code)\n{\n    coreclr_shutdown_2_ptr coreclr_shutdown2_func = nullptr;\n    if (!try_get_export(coreclr_mod, \"coreclr_shutdown_2\", (void**)&coreclr_shutdown2_func))\n    {\n        return -1;\n    }\n\n    int latched_exit_code = 0;\n    int result = coreclr_shutdown2_func(CurrentClrInstance, CurrentAppDomainId, &latched_exit_code);\n    if (FAILED(result))\n    {\n        pal::fprintf(stderr, W(\"coreclr_shutdown_2 failed - Error: 0x%08x\\n\"), result);\n        exit_code = -1;\n    }\n\n    if (exit_code != -1)\n        exit_code = latched_exit_code;\n\n    ::free((void*)s_core_libs_path);\n    ::free((void*)s_core_root_path);\n    return exit_code;\n}\n\n// Display the command line options\nstatic void display_usage()\n{\n    pal::fprintf(\n        stderr,\n        W(\"USAGE: corerun [OPTIONS] assembly [ARGUMENTS]\\n\")\n        W(\"\\n\")","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/hosts/corerun/corerun.cpp#L671-L707","documentation":"Printed at src/coreclr/hosts/corerun/corerun.cpp:689 when coreclr_shutdown_2 returns a failing HRESULT during runtime teardown. Shutdown failures are usually non-fatal for the program result (the process is exiting anyway), but indicate a leak, a lingering thread, or an unloading AppDomain error.","triggerScenarios":"Triggered inside corerun_shutdown when the resolved coreclr_shutdown_2 export returns FAILED(result). Typical causes: background managed threads still running, unhandled exceptions during finalization, or a bug in the runtime's unload path.","commonSituations":"Observed when the managed program started background tasks that were not stopped, when native host code holds references preventing clean unload, or with runtime builds that have known shutdown bugs.","solutions":["Ensure all managed background threads/tasks are stopped before Main returns.","Treat the exit code as -1 only when shutdown actually failed; otherwise prefer the latched exit code.","Upgrade the runtime to a version with shutdown-path fixes if the HRESULT points to a known bug.","If reproducible, capture a dump at shutdown to inspect outstanding handles/threads."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// corerun_shutdown is internal; users cannot catch it. Instead, ensure clean state before exit:\n// stop all background tasks in Main, then return. The host's exit code reflects -1 only on real failure.","preventionTips":["Stop all managed background threads/tasks before Main returns.","Do not hold native references into the runtime past execution.","Use a runtime version with known shutdown fixes.","Capture a shutdown dump if the warning is reproducible."],"tags":["coreclr","corerun","shutdown","host"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}