{"record":{"id":"7fb43ae0892932d5","repo":"apple/pkl","slug":"fatal-failed-to-detach-response-dispatch-thread-f","errorCode":null,"errorMessage":"fatal: failed to detach response dispatch thread from isolate.\n","messagePattern":"fatal: failed to detach response dispatch thread from isolate\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libpkl/src/main/c/pkl.c","lineNumber":76,"sourceCode":"#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);\n\t\t// message was allocated on the Java side via UnmanagedMemory.malloc, which maps onto\n\t\t// the platform's malloc/free; ownership passes to us here.\n\t\tfree(message);\n\t}\n\n#ifdef _WIN32\n  return 0;\n#else","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/libpkl/src/main/c/pkl.c#L58-L94","documentation":"Fatal check in libpkl's pkl_dispatch_worker: after each poll, graal_detach_thread must release the worker thread from the isolate; non-zero return triggers this message and abort. A failed detach leaves the thread bound to the isolate and usually indicates isolate state corruption or teardown during dispatch.","triggerScenarios":"Thrown at libpkl/src/main/c/pkl.c:76 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Stop the message server before tearing down the isolate so the worker exits cleanly between polls.","Verify pkl_close is called from the correct thread and only once."],"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"}