aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-09-21 18:59:01 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-21 18:59:01 -0700
commite34ff6133908d0f975e13f943cd434f28b74a9a6 (patch)
tree70b03ed9e0edea22cd733ad4a5785519ec5eff59
parent8684a590290b65a23626df67791d7b54eaf4ccaf (diff)
downloadbun-e34ff6133908d0f975e13f943cd434f28b74a9a6.tar.gz
bun-e34ff6133908d0f975e13f943cd434f28b74a9a6.tar.zst
bun-e34ff6133908d0f975e13f943cd434f28b74a9a6.zip
Don't use arena in node:fs (#5863)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r--bench/snippets/rmdir.mjs22
-rw-r--r--src/bun.js/node/node_fs.zig12
-rw-r--r--src/bun.js/node/node_fs_stat_watcher.zig2
-rw-r--r--src/bun.js/node/types.zig2
-rw-r--r--test/js/node/fs/fs.test.ts19
5 files changed, 49 insertions, 8 deletions
diff --git a/bench/snippets/rmdir.mjs b/bench/snippets/rmdir.mjs
new file mode 100644
index 000000000..258d69097
--- /dev/null
+++ b/bench/snippets/rmdir.mjs
@@ -0,0 +1,22 @@
+import { tmpdir } from "node:os";
+import { promises, existsSync, mkdirSync } from "node:fs";
+const count = 1024 * 12;
+
+var queue = new Array(count);
+var paths = new Array(count);
+for (let i = 0; i < count; i++) {
+ const path = `${tmpdir()}/${Date.now()}.rm.dir${i}`;
+ try {
+ mkdirSync(path);
+ } catch (e) {}
+ paths[i] = path;
+ queue[i] = promises.rmdir(path);
+}
+
+await Promise.all(queue);
+
+for (let i = 0; i < count; i++) {
+ if (existsSync(paths[i])) {
+ throw new Error(`Path ${paths[i]} was not removed`);
+ }
+}
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig
index 752d0e2fb..a07e75ee2 100644
--- a/src/bun.js/node/node_fs.zig
+++ b/src/bun.js/node/node_fs.zig
@@ -1074,7 +1074,7 @@ pub const Arguments = struct {
}
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Stat {
- const path = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const path = PathLike.fromJS(ctx, arguments, exception) orelse {
if (exception.* == null) {
JSC.throwInvalidArguments(
"path must be a string or TypedArray",
@@ -1649,7 +1649,7 @@ pub const Arguments = struct {
}
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Readdir {
- const path = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const path = PathLike.fromJS(ctx, arguments, exception) orelse {
if (exception.* == null) {
JSC.throwInvalidArguments(
"path must be a string or TypedArray",
@@ -2917,7 +2917,7 @@ pub const Arguments = struct {
}
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?CopyFile {
- const src = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const src = PathLike.fromJS(ctx, arguments, exception) orelse {
if (exception.* == null) {
JSC.throwInvalidArguments(
"src must be a string or buffer",
@@ -2931,7 +2931,7 @@ pub const Arguments = struct {
if (exception.* != null) return null;
- const dest = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const dest = PathLike.fromJS(ctx, arguments, exception) orelse {
src.deinit();
if (exception.* == null) {
@@ -2981,7 +2981,7 @@ pub const Arguments = struct {
}
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Cp {
- const src = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const src = PathLike.fromJS(ctx, arguments, exception) orelse {
if (exception.* == null) {
JSC.throwInvalidArguments(
"src must be a string or buffer",
@@ -2995,7 +2995,7 @@ pub const Arguments = struct {
if (exception.* != null) return null;
- const dest = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
+ const dest = PathLike.fromJS(ctx, arguments, exception) orelse {
defer src.deinit();
if (exception.* == null) {
JSC.throwInvalidArguments(
diff --git a/src/bun.js/node/node_fs_stat_watcher.zig b/src/bun.js/node/node_fs_stat_watcher.zig
index c2690c200..3bf262f07 100644
--- a/src/bun.js/node/node_fs_stat_watcher.zig
+++ b/src/bun.js/node/node_fs_stat_watcher.zig
@@ -198,7 +198,7 @@ pub const StatWatcher = struct {
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Arguments {
const vm = ctx.vm();
- const path = PathLike.fromJS(ctx, arguments, exception) orelse {
+ const path = PathLike.fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception) orelse {
if (exception.* == null) {
JSC.throwInvalidArguments(
"filename must be a string or TypedArray",
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 7e9cdcd2d..4a650dbaf 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -802,7 +802,7 @@ pub const PathLike = union(Tag) {
}
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?PathLike {
- return fromJSWithAllocator(ctx, arguments, arguments.arena.allocator(), exception);
+ return fromJSWithAllocator(ctx, arguments, bun.default_allocator, exception);
}
pub fn fromJSWithAllocator(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, allocator: std.mem.Allocator, exception: JSC.C.ExceptionRef) ?PathLike {
const arg = arguments.next() orelse return null;
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index f9ef38fe8..78b6c21f3 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -1062,6 +1062,25 @@ describe("rmdir", () => {
done();
});
});
+
+ it("removes a dir x 512", async () => {
+ var queue = new Array(512);
+ var paths = new Array(512);
+ for (let i = 0; i < 512; i++) {
+ const path = `${tmpdir()}/${Date.now()}.rm.dir${i}`;
+ try {
+ mkdirSync(path);
+ } catch (e) {}
+ paths[i] = path;
+ queue[i] = promises.rmdir(path);
+ }
+
+ await Promise.all(queue);
+
+ for (let i = 0; i < 512; i++) {
+ expect(existsSync(paths[i])).toBe(false);
+ }
+ });
it("does not remove a dir with a file in it", async () => {
const path = `${tmpdir()}/${Date.now()}.rm.dir`;
try {