GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: stop recursive mkdir from retrying ENOENT forever by marcopiraccini · Pull Request #66340 · nodejs/node

fs: stop recursive mkdir from retrying ENOENT forever #66340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nodejs-github-bot merged 2 commits into nodejs:main from marcopiraccini:fs-mkdirp-enoent-loop
Sep 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fs: stop recursive mkdir from retrying ENOENT forever #66340

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
03cf268
fs: stop recursive mkdir from retrying ENOENT forever
marcopiraccini Sep 27, 2026
c4a2e89
fixup! fs: stop recursive mkdir from retrying ENOENT forever
marcopiraccini Sep 27, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 11 additions & 0 deletions 11 src/node_file-inl.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "node_file.h"
#include "req_wrap-inl.h"

#include <algorithm>

namespace node {
namespace fs {

Expand All @@ -27,6 +29,15 @@ void FSContinuationData::MaybeSetFirstPath(const std::string& path) {
}
}

bool FSContinuationData::ShouldRetryENOENT(const std::string& path) {
if (std::find(enoent_paths_.begin(), enoent_paths_.end(), path) !=
enoent_paths_.end()) {
return false;
}
enoent_paths_.push_back(path);
return true;
}

std::string FSContinuationData::PopPath() {
CHECK(!paths_.empty());
std::string path = std::move(paths_.back());
Expand Down
8 changes: 8 additions & 0 deletions 8 src/node_file.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ typedef void (*uv_fs_callback_t)(uv_fs_t*);

void FSContinuationData::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("paths", paths_);
tracker->TrackField("enoent_paths", enoent_paths_);
}

FileHandleReadWrap::~FileHandleReadWrap() = default;
Expand Down Expand Up @@ -1966,6 +1967,9 @@ int MKDirpSync(uv_loop_t* loop,
std::string dirname =
next_path.substr(0, next_path.find_last_of(kPathSeparator));
if (dirname != next_path) {
if (!req_wrap->continuation_data()->ShouldRetryENOENT(next_path)) {
return err;
}
req_wrap->continuation_data()->PushPath(std::move(next_path));
req_wrap->continuation_data()->PushPath(std::move(dirname));
} else if (req_wrap->continuation_data()->paths().empty()) {
Expand Down Expand Up @@ -2047,6 +2051,10 @@ int MKDirpAsync(
std::string dirname =
path.substr(0, path.find_last_of(kPathSeparator));
if (dirname != path) {
if (!req_wrap->continuation_data()->ShouldRetryENOENT(path)) {
req_wrap->continuation_data()->Done(err);
break;
}
req_wrap->continuation_data()->PushPath(path);
req_wrap->continuation_data()->PushPath(std::move(dirname));
} else if (req_wrap->continuation_data()->paths().empty()) {
Expand Down
4 changes: 4 additions & 0 deletions 4 src/node_file.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class FSContinuationData : public MemoryRetainer {
inline std::string PopPath();
// Used by mkdirp to track the first path created:
inline void MaybeSetFirstPath(const std::string& path);
// Used by mkdirp to retry a path that failed with ENOENT only once: its
// parent has been created or checked by then, so retrying again cannot help.
inline bool ShouldRetryENOENT(const std::string& path);
inline void Done(int result);

int mode() const { return mode_; }
Expand All @@ -129,6 +132,7 @@ class FSContinuationData : public MemoryRetainer {
uv_fs_t* req_;
int mode_;
std::vector<std::string> paths_;
std::vector<std::string> enoent_paths_;
std::string first_path_;
};

Expand Down
22 changes: 22 additions & 0 deletions 22 test/parallel/test-fs-mkdir-recursive-enoent.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
// Refs: https://github.com/nodejs/node/issues/66268
// On procfs, mkdir fails with ENOENT although the parent exists. A recursive
// mkdir must report the error instead of retrying forever.
const common = require('../common');
const fs = require('fs');

if (!common.isLinux) common.skip('procfs is Linux only');

const assert = require('assert');
const dir = `/proc/node-test-${process.pid}`;
const expected = { code: 'ENOENT', syscall: 'mkdir' };

assert.throws(() => fs.mkdirSync(dir, { recursive: true }), expected);

fs.mkdir(dir, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, expected.code);
assert.strictEqual(err.syscall, expected.syscall);
}));
Comment thread
Comment on lines +16 to +19

@atlowChemi atlowChemi Sep 27, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified to

Suggested change
fs.mkdir(dir, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, expected.code);
assert.strictEqual(err.syscall, expected.syscall);
}));
fs.mkdir(dir, { recursive: true }, common.expectsError(expected));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

assert.rejects(fs.promises.mkdir(dir, { recursive: true }), expected)
.then(common.mustCall());
23 changes: 23 additions & 0 deletions 23 test/parallel/test-heapdump-fs-mkdir-recursive.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

// This tests heap snapshot integration of a pending recursive mkdir.

const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { validateByRetainingPath } = require('../common/heap');
const assert = require('assert');
const fs = require('fs');

tmpdir.refresh();

{
const nodes = validateByRetainingPath('Node / FSContinuationData', []);
assert.strictEqual(nodes.length, 0);
}

fs.mkdir(tmpdir.resolve('a', 'b'), { recursive: true }, common.mustSucceed());

{
const nodes = validateByRetainingPath('Node / FSContinuationData', []);
assert.strictEqual(nodes.length, 1);
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.