{"record":{"id":"8f1bd87adb4ca078","repo":"apache/hadoop","slug":"threadjoin-waitforsingleobject-unexpected-error","errorCode":null,"errorMessage":"threadJoin: WaitForSingleObject unexpected error %d\n","messagePattern":"threadJoin: WaitForSingleObject unexpected error (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread.c","lineNumber":61,"sourceCode":"  } else {\n    ret = GetLastError();\n    fprintf(stderr, \"threadCreate: CreateThread failed with error %d\\n\", ret);\n  }\n  return ret;\n}\n\nint threadJoin(const thread *t) {\n  DWORD ret = WaitForSingleObject(t->id, INFINITE);\n  switch (ret) {\n  case WAIT_OBJECT_0:\n    break;\n  case WAIT_FAILED:\n    ret = GetLastError();\n    fprintf(stderr, \"threadJoin: WaitForSingleObject failed with error %d\\n\",\n      ret);\n    break;\n  default:\n    fprintf(stderr, \"threadJoin: WaitForSingleObject unexpected error %d\\n\",\n      ret);\n    break;\n  }\n  return ret;\n}\n","sourceCodeStart":43,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread.c#L43-L67","documentation":"Windows threadJoin: WaitForSingleObject returned a value that is neither WAIT_OBJECT_0 nor WAIT_FAILED. With an INFINITE timeout on a thread handle this should be unreachable (WAIT_TIMEOUT and friends require a timeout), so it indicates handle-type confusion (waiting on a non-thread object) or corrupted handle data. The raw value is printed and returned as the join result.","triggerScenarios":"Passing a HANDLE that is not a thread (event/mutex/file) into threadJoin; memory corruption of the thread struct's stored handle.","commonSituations":"Almost never seen; when it appears, treat it as a corruption or API-misuse smoke signal in the surrounding code.","solutions":["Capture the raw value and confirm the HANDLE originated from threadCreate on the same struct","Run with Application Verifier (handles) or a debugger to detect handle misuse","Audit for writes past the end of the thread struct"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"DWORD rc = WaitForSingleObject(t.id, INFINITE);\nif (rc != WAIT_OBJECT_0) {\n    /* unexpected: verify the handle is a thread and not corrupted */\n    assert(rc == WAIT_FAILED); /* else treat as corruption smoke */\n}","preventionTips":["Only pass handles returned by threadCreate into threadJoin","Run Application Verifier handle checks when this appears","Treat as a memory-corruption smoke signal and investigate surrounding writes"],"tags":["libhdfs","windows","waitforsingleobject","thread-join","win32"],"backgroundTag":"waitforsingleobject-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}