{"record":{"id":"e268d09b843b1511","repo":"apache/hadoop","slug":"threadcreate-createthread-failed-with-error-d","errorCode":null,"errorMessage":"threadCreate: CreateThread failed with error %d\n","messagePattern":"threadCreate: CreateThread failed with error (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread.c","lineNumber":45,"sourceCode":" *\n * @param toRun thread to run\n * @return DWORD result of running thread (always 0)\n */\nstatic DWORD WINAPI runThread(LPVOID toRun) {\n  const thread *t = toRun;\n  t->start(t->arg);\n  return 0;\n}\n\nint threadCreate(thread *t) {\n  DWORD ret = 0;\n  HANDLE h;\n  h = CreateThread(NULL, 0, runThread, t, 0, NULL);\n  if (h) {\n    t->id = h;\n  } 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;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread.c#L27-L63","documentation":"Windows port of threadCreate: CreateThread returned NULL and GetLastError supplied the code — typically ERROR_NOT_ENOUGH_MEMORY (1455, cannot reserve/commit the thread stack) under commit-limit pressure, since CreateThread commits 1MB of stack by default. The thread never starts, so later work or joins fail downstream.","triggerScenarios":"Spawning threads on Windows near the commit limit (RAM + pagefile), under job-object memory caps, or with many simultaneous thread creations.","commonSituations":"Windows services with small pagefiles; bursty thread-pool growth; CI agents under memory pressure.","solutions":["Look up the code: 1455 → enlarge the pagefile/commit limit or stagger/bound thread creation","Bound the thread pool to a fixed size","If running under a job object, check its memory limits"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"/* Windows: check commit headroom before a burst of thread creation */\nMEMORYSTATUSEX st = { sizeof(st) };\nGlobalMemoryStatusEx(&st);\nif (st.ullAvailPageFile < 64ULL * 1024 * 1024) {\n    /* too little commit left for 1MB stacks; defer spawning */\n}","typeGuard":null,"tryCatchPattern":"if (threadCreate(&t) != 0) {\n    /* GetLastError code printed; fall back to inline execution */\n    t.start(t.arg);\n}","preventionTips":["Bound the thread pool; stagger creation bursts","Size the pagefile/commit limit for the peak thread count","Watch job-object memory caps when running under one"],"tags":["libhdfs","windows","createthread","thread-creation","win32"],"backgroundTag":"thread-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}