{"record":{"id":"8303be21ca9c2192","repo":"apple/pkl","slug":"fatal-failed-to-tear-down-graal-isolate","errorCode":null,"errorMessage":"fatal: failed to tear down graal isolate.\n","messagePattern":"fatal: failed to tear down graal isolate\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libpkl/src/main/c/pkl.c","lineNumber":239,"sourceCode":"\t\t}\n\t\treturn -1;\n\t}\n\n\tgraal_isolatethread_t *thread = graal_get_current_thread(pexec->isolate);\n\tif (thread != pexec->isolateThread) {\n\t\tif (error != NULL) {\n\t\t\terror->message = \"called into pkl_close from different thread\";\n\t\t}\n\t\treturn PKL_ERR_THREAD;\n\t}\n\n\t// pkl_internal_server_stop unblocks queue_thread's pending/next poll call, so the join\n\t// below is guaranteed to return; only then is it safe to tear down the isolate.\n\tpkl_internal_server_stop(thread);\n\tpkl_stop_dispatch_worker(pexec);\n\n\tif (graal_tear_down_isolate(thread) != 0) {\n\t\tfprintf(stderr, \"fatal: failed to tear down graal isolate.\\n\");\n\t\tabort();\n\t}\n\n\tfree(pexec);\n\tif (error != NULL) {\n\t\terror->message = NULL;\n\t}\n\treturn 0;\n}\n\nconst char* pkl_version() {\n\treturn PKL_VERSION;\n}\n","sourceCodeStart":221,"sourceCodeEnd":253,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/libpkl/src/main/c/pkl.c#L221-L253","documentation":"Fatal check in pkl_close: graal_tear_down_isolate returned non-zero, meaning the GraalVM isolate could not be shut down cleanly; the process aborts because a half-torn-down isolate is unrecoverable. Typically indicates lingering threads attached to, or work still running in, the isolate.","triggerScenarios":"Thrown at libpkl/src/main/c/pkl.c:239 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all evaluation work and the dispatch worker are stopped before pkl_close (pkl_internal_server_stop already does this — check for extra attached threads).","Call pkl_close exactly once, from the same thread that ran pkl_init."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}