Skip to content

Commit 98247e9

Browse files
committed
vfs: reset state after failed mount
A failed mount registration should leave the VirtualFileSystem instance unmounted so it does not report stale mount state or handle paths under the rejected mount point. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent d7aca7e commit 98247e9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/internal/vfs/file_system.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ class VirtualFileSystem {
143143
this[kMounted] = true;
144144
debug('mount %s', this[kMountPoint]);
145145
loadVfsSetup();
146-
registerVFS(this);
146+
try {
147+
registerVFS(this);
148+
} catch (err) {
149+
this[kMountPoint] = null;
150+
this[kMounted] = false;
151+
throw err;
152+
}
147153
return this;
148154
}
149155

test/parallel/test-vfs-mount-errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const { vfsState } = require('internal/fs/utils');
1616
const baseMountPoint = path.resolve('/tmp/vfs-mount-errors-' + process.pid);
1717
let mountCounter = 0;
1818
const nextMount = () => baseMountPoint + '-' + (mountCounter++);
19+
function assertUnmounted(instance, mountPoint) {
20+
assert.strictEqual(instance.mounted, false);
21+
assert.strictEqual(instance.mountPoint, null);
22+
assert.strictEqual(instance.shouldHandle(mountPoint), false);
23+
}
1924

2025
// EXDEV: rename across two different VFS instances
2126
{
@@ -130,13 +135,15 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++);
130135
const b = vfs.create();
131136
a.mount(parent);
132137
assert.throws(() => b.mount(child), { code: 'ERR_INVALID_STATE' });
138+
assertUnmounted(b, child);
133139
a.unmount();
134140

135141
// Reverse direction: child first, then parent rejected
136142
const c = vfs.create();
137143
const d = vfs.create();
138144
c.mount(child);
139145
assert.throws(() => d.mount(parent), { code: 'ERR_INVALID_STATE' });
146+
assertUnmounted(d, parent);
140147
c.unmount();
141148
}
142149

@@ -147,6 +154,7 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++);
147154
const b = vfs.create();
148155
a.mount(m);
149156
assert.throws(() => b.mount(m), { code: 'ERR_INVALID_STATE' });
157+
assertUnmounted(b, m);
150158
a.unmount();
151159
}
152160

0 commit comments

Comments
 (0)