apache/hadoop · warning

detachCurrentThreadFromJvm: GetJavaVM failed with error %d

Error message

detachCurrentThreadFromJvm: GetJavaVM failed with error %d

What it means

Windows counterpart of the POSIX TLS destructor: during DLL_THREAD_DETACH/PROCESS_DETACH, detachCurrentThreadFromJvm resolves the VM with GetJavaVM before detaching; a non-zero return logs this warning and describes any pending exception. The exception strings and state are still freed afterwards, so this is a teardown-time warning.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c:55

 */
static void detachCurrentThreadFromJvm()
{
  struct ThreadLocalState *state = NULL;
  JNIEnv *env = NULL;
  JavaVM *vm;
  jint ret;
  char thr_name[MAXTHRID];

  if (threadLocalStorageGet(&state) || !state) {
    return;
  }
  env = state->env;
  if ((env == NULL) || (*env == NULL)) {
    return;
  }
  ret = (*env)->GetJavaVM(env, &vm);
  if (ret) {
    fprintf(stderr,
      "detachCurrentThreadFromJvm: GetJavaVM failed with error %d\n",
      ret);
    (*env)->ExceptionDescribe(env);
  } else {
    ret = (*vm)->DetachCurrentThread(vm);

    if (ret != JNI_OK) {
      (*env)->ExceptionDescribe(env);
      get_current_thread_id(env, thr_name, MAXTHRID);

      fprintf(stderr, "detachCurrentThreadFromJvm: Unable to detach thread %s "
          "from the JVM. Error code: %d\n", thr_name, ret);
    }
  }

  /* Free exception strings */
  if (state->lastExceptionStackTrace) free(state->lastExceptionStackTrace);
  if (state->lastExceptionRootCause) free(state->lastExceptionRootCause);

View on GitHub (pinned to 2add963021)

Solutions

  1. If limited to process exit, treat as benign noise
  2. If seen mid-run, audit other JNI components for double-detach
  3. Ensure HDFS work completes before library unload
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: DLL detach after the JVM is already gone or the JNIEnv is invalid — unload ordering at process exit, or another component having detached the thread first.

Common situations: Windows services unloading libhdfs while JVM shutdown races; processes mixing several JNI-capable native libraries.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/24e763b30933f08c. Report an issue: GitHub.