apache/hadoop · warning

hdfsThreadDestructor: GetJavaVM failed with error %d

Error message

hdfsThreadDestructor: GetJavaVM failed with error %d

What it means

At thread exit, the TLS destructor libhdfs registered via pthread_key_create tries to detach the thread from the embedded JVM. It first resolves the VM with GetJavaVM on the thread's JNIEnv; a non-zero return (e.g. JNI_EDETACHED, or the env is already invalid during teardown) prints this warning, describes any pending exception, and continues. The state is still freed, so impact is limited to a leaked attachment.

Source

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

 * is destroyed.
 *
 * @param v         The thread-local data
 */
void hdfsThreadDestructor(void *v)
{
  JavaVM *vm;
  struct ThreadLocalState *state = (struct ThreadLocalState*)v;
  JNIEnv *env = state->env;;
  jint ret;
  jthrowable jthr;
  char thr_name[MAXTHRID];

  /* Detach the current thread from the JVM */
  if ((env != NULL) && (*env != NULL)) {
    ret = (*env)->GetJavaVM(env, &vm);

    if (ret != 0) {
      fprintf(stderr, "hdfsThreadDestructor: GetJavaVM failed with error %d\n",
        ret);
      jthr = (*env)->ExceptionOccurred(env);
      if (jthr) {
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
      }
    } else {
      ret = (*vm)->DetachCurrentThread(vm);

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

        fprintf(stderr, "hdfsThreadDestructor: Unable to detach thread %s "

View on GitHub (pinned to 2add963021)

Solutions

  1. If seen only at process shutdown with no functional failure, treat as benign log noise
  2. If seen mid-run, audit other in-process JNI components for double-detach of the same thread
  3. Ensure HDFS work on the thread completes before triggering JVM teardown
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: Thread exit during JVM shutdown; the thread already detached by another native library that manages JNI attachment itself, leaving GetJavaVM unable to resolve the VM.

Common situations: Mixing libhdfs with other JNI libraries that also call DetachCurrentThread; exit-time ordering races; harmless but noisy lines in production logs during shutdown.

Related errors


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