{"record":{"id":"0ca23223250cee66","repo":"apache/hadoop","slug":"hdfsopenfile-s-failed-error-d-s-n","errorCode":null,"errorMessage":"hdfsOpenFile(%s) failed: error %d (%s)\\n","messagePattern":"hdfsOpenFile\\((.+?)\\) failed: error (.+?) \\((.+?)\\)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/vecsum.c","lineNumber":485,"sourceCode":"    pinfo = hdfsGetPathInfo(ldata->fs, opts->path);\n    if (!pinfo) {\n        int err = errno;\n        fprintf(stderr, \"hdfsGetPathInfo(%s) failed: error %d (%s).  \"\n                \"Attempting to re-create file.\\n\",\n            opts->path, err, strerror(err));\n        if (libhdfs_data_create_file(ldata, opts))\n            goto error;\n    } else if (pinfo->mSize != opts->length) {\n        fprintf(stderr, \"hdfsGetPathInfo(%s) failed: length was %lld, \"\n                \"but we want length %lld.  Attempting to re-create file.\\n\",\n                opts->path, (long long)pinfo->mSize, (long long)opts->length);\n        if (libhdfs_data_create_file(ldata, opts))\n            goto error;\n    }\n    ldata->file = hdfsOpenFile(ldata->fs, opts->path, O_RDONLY, 0, 0, 0);\n    if (!ldata->file) {\n        int err = errno;\n        fprintf(stderr, \"hdfsOpenFile(%s) failed: error %d (%s)\\n\",\n            opts->path, err, strerror(err));\n        goto error;\n    }\n    ldata->length = opts->length;\n    return ldata;\n\nerror:\n    if (pinfo)\n        hdfsFreeFileInfo(pinfo, 1);\n    if (ldata)\n        libhdfs_data_free(ldata);\n    return NULL;\n}\n\nstatic int check_byte_size(int byte_size, const char *const str)\n{\n    if (byte_size % sizeof(double)) {\n        fprintf(stderr, \"%s is not a multiple \"","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/vecsum.c#L467-L503","documentation":"vecsum (libhdfs read microbenchmark) calls hdfsOpenFile(fs, path, O_RDONLY, ...) after ensuring the target file exists at the requested length. If libhdfs returns NULL the tool prints this message with the captured errno and unwinds to its error path, aborting the benchmark run.","triggerScenarios":"hdfsOpenFile() returning NULL: the file was deleted between hdfsGetPathInfo() and the open, permission denied on the path, the NameNode is unreachable or authentication fails, or the libhdfs process is configured with the wrong fs.defaultFS / CLASSPATH so it connects to the wrong cluster.","commonSituations":"Running the vecsum test binary with a stale CLASSPATH or hdfs-site.xml, typo in the -p path argument, file removed by another process or a previous interrupted run, secure cluster without a valid Kerberos TGT (kinit not done).","solutions":["Read the errno value in the message and resolve it first (ENOENT = wrong/deleted path, EACCES = permissions, ECONNREFUSED/UnknownHost = NameNode config).","Verify the file exists with the expected size: hdfs dfs -ls <path>.","Confirm connectivity and config used by the native client (CLASSPATH env, fs.defaultFS in the XML on the classpath).","Re-run with a valid Kerberos ticket / correct user if the cluster is secure."],"exampleFix":"# before\nvecsum -t libhdfs -p /bad/path/to/file   # hdfsOpenFile failed: error 2 (No such file or directory)\n# after\nhdfs dfs -ls /bench/vecsum              # confirm path + length, then\nvecsum -t libhdfs -p /bench/vecsum","handlingStrategy":"validation","validationCode":"/* validate before opening */\nif (hdfsExists(fs, path) != 0) {\n    fprintf(stderr, \"path %s missing; create it first\\n\", path);\n    return -1;\n}\nhdfsFileInfo *info = hdfsGetPathInfo(fs, path);\nif (!info) { /* handle */ }\nldata->file = hdfsOpenFile(fs, path, O_RDONLY, 0, 0, 0);","typeGuard":null,"tryCatchPattern":"/* C idiom: NULL check + capture errno immediately (before any other call) */\nldata->file = hdfsOpenFile(fs, path, O_RDONLY, 0, 0, 0);\nif (!ldata->file) {\n    int err = errno;  /* capture before other syscalls overwrite it */\n    switch (err) {\n    case ENOENT: /* missing path */ break;\n    case EACCES: /* permissions */ break;\n    default:     /* connectivity/auth */ break;\n    }\n}","preventionTips":["Check hdfsExists()/hdfsGetPathInfo() for the path before hdfsOpenFile().","Capture errno into a local immediately on NULL return; any later libc call can clobber it.","Validate the client config (fs.defaultFS, CLASSPATH) with a trivial hdfsListDirectory call before starting benchmark runs.","In scripts, run vecsum only after confirming the file exists at the expected length via the hdfs CLI."],"tags":["hdfs","libhdfs","c","errno","file-open","vecsum"],"backgroundTag":"hdfs-file-open-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}