{"record":{"id":"c796a20a0d7d1e5c","repo":"apple/pkl","slug":"fatal-failed-to-attach-response-dispatch-thread-t","errorCode":null,"errorMessage":"fatal: failed to attach response dispatch thread to isolate.","messagePattern":"fatal: failed to attach response dispatch thread to isolate\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libpkl/src/main/c/pkl.c","lineNumber":68,"sourceCode":"};\n\n/**\n * Polls for messages coming from Pkl and sends them back to the handler.\n *\n * Ensures that calls into Pkl are wrapped with graal_attach_thread/graal_detach_thread, and\n * calls back to the handler are _not_ inside the GraalVM thread context.\n */\n#ifdef _WIN32\nstatic DWORD WINAPI pkl_dispatch_worker(LPVOID arg) {\n#else\nstatic void* pkl_dispatch_worker(void *arg) {\n#endif\n\tconst pkl_exec_t *pexec = (pkl_exec_t*) arg;\n\n\tfor (;;) {\n\t\tgraal_isolatethread_t *thread;\n\t\tif (graal_attach_thread(pexec->isolate, &thread) != 0) {\n\t\t\tfprintf(stderr,\n\t\t\t\t\t\"fatal: failed to attach response dispatch thread to isolate.\\n\");\n\t\t\tabort();\n\t\t}\n\n\t\tchar *message = NULL;\n\t\tconst int length = pkl_internal_poll_response(thread, &message);\n\n\t\tif (graal_detach_thread(thread) != 0) {\n\t\t\tfprintf(stderr,\n\t\t\t\t\t\"fatal: failed to detach response dispatch thread from isolate.\\n\");\n\t\t\tabort();\n\t\t}\n\n\t\tif (length < 0) {\n\t\t\t// pkl_internal_server_stop has been called and the queue is drained\n\t\t\tbreak;\n\t\t}\n\t\tpexec->handler(length, message, pexec->userData);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/libpkl/src/main/c/pkl.c#L50-L86","documentation":"Fatal check in libpkl's pkl_dispatch_worker: before polling for Pkl responses, the worker thread must attach to the GraalVM isolate via graal_attach_thread; a non-zero return means the native thread could not join the isolate, so the process aborts. Typically caused by isolate teardown concurrent with dispatch or resource exhaustion.","triggerScenarios":"Thrown at libpkl/src/main/c/pkl.c:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure pkl_close is not racing the dispatch worker (close only after stopping message traffic).","Check GraalVM native-image logs for isolate creation/attach limits."],"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"}