apple/pkl · error

fatal: failed to detach response dispatch thread from…

Error message

fatal: failed to detach response dispatch thread from isolate.

What it means

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.

Solutions

  1. Stop the message server before tearing down the isolate so the worker exits cleanly between polls.
  2. Verify pkl_close is called from the correct thread and only once.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at libpkl/src/main/c/pkl.c:76 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/7fb43ae0892932d5. Report an issue: GitHub.

Appendix: source

Thrown at libpkl/src/main/c/pkl.c:76

#ifdef _WIN32
static DWORD WINAPI pkl_dispatch_worker(LPVOID arg) {
#else
static void* pkl_dispatch_worker(void *arg) {
#endif
	const pkl_exec_t *pexec = (pkl_exec_t*) arg;

	for (;;) {
		graal_isolatethread_t *thread;
		if (graal_attach_thread(pexec->isolate, &thread) != 0) {
			fprintf(stderr,
					"fatal: failed to attach response dispatch thread to isolate.\n");
			abort();
		}

		char *message = NULL;
		const int length = pkl_internal_poll_response(thread, &message);

		if (graal_detach_thread(thread) != 0) {
			fprintf(stderr,
					"fatal: failed to detach response dispatch thread from isolate.\n");
			abort();
		}

		if (length < 0) {
			// pkl_internal_server_stop has been called and the queue is drained
			break;
		}
		pexec->handler(length, message, pexec->userData);
		// message was allocated on the Java side via UnmanagedMemory.malloc, which maps onto
		// the platform's malloc/free; ownership passes to us here.
		free(message);
	}

#ifdef _WIN32
  return 0;
#else

View on GitHub (pinned to f3efcbfc9b)