aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-09-12 20:47:14 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-09-12 20:47:14 -0700
commitec251863d149db3b2bf07d106c5aa7a2074e5301 (patch)
tree92baf39c3424ef4f737ea4b5ef56098cc2bd579d
parent85bf54a3ac2b737497e32219f78412ff9a02dbdb (diff)
downloadbun-ec251863d149db3b2bf07d106c5aa7a2074e5301.tar.gz
bun-ec251863d149db3b2bf07d106c5aa7a2074e5301.tar.zst
bun-ec251863d149db3b2bf07d106c5aa7a2074e5301.zip
track registered one shot fds
-rw-r--r--src/bun.js/base.zig32
-rw-r--r--src/bun.js/javascript.zig6
2 files changed, 26 insertions, 12 deletions
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index 8f65cf42e..087010dbf 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -2168,10 +2168,19 @@ pub const FilePoll = struct {
var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @intFromPtr(Pollable.init(this).ptr()) } };
+ var op = if (this.isRegistered() or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD;
+
+ if (op == linux.EPOLL.CTL_ADD and this.flags.contains(.one_shot)) {
+ var gpe = JSC.VirtualMachine.get().registered_one_shot_epoll_fds.getOrPut(fd);
+ if (gpe.found_existing) {
+ op = linux.EPOLL.CTL_MOD;
+ }
+ }
+
const ctl = linux.epoll_ctl(
watcher_fd,
- if (this.isRegistered() or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD,
- @as(std.os.fd_t, @intCast(fd)),
+ op,
+ @intCast(fd),
&event,
);
this.flags.insert(.was_ever_registered);
@@ -2310,24 +2319,23 @@ pub const FilePoll = struct {
return JSC.Maybe(void).success;
};
- if (comptime !Environment.isLinux) {
- if (this.flags.contains(.needs_rearm)) {
- log("unregister: {s} ({d}) skipped due to needs_rearm", .{ @tagName(flag), fd });
- this.flags.remove(.poll_process);
- this.flags.remove(.poll_readable);
- this.flags.remove(.poll_process);
- this.flags.remove(.poll_machport);
- return JSC.Maybe(void).success;
- }
+ if (this.flags.contains(.needs_rearm)) {
+ log("unregister: {s} ({d}) skipped due to needs_rearm", .{ @tagName(flag), fd });
+ this.flags.remove(.poll_process);
+ this.flags.remove(.poll_readable);
+ this.flags.remove(.poll_process);
+ this.flags.remove(.poll_machport);
+ return JSC.Maybe(void).success;
}
log("unregister: {s} ({d})", .{ @tagName(flag), fd });
if (comptime Environment.isLinux) {
+ _ = JSC.VirtualMachine.get().registered_one_shot_epoll_fds.remove(fd);
const ctl = linux.epoll_ctl(
watcher_fd,
linux.EPOLL.CTL_DEL,
- @as(std.os.fd_t, @intCast(fd)),
+ @intCast(fd),
null,
);
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 752fcb3a4..2733d46b4 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -526,6 +526,8 @@ pub const VirtualMachine = struct {
debugger: ?Debugger = null,
has_started_debugger: bool = false,
+ registered_one_shot_epoll_fds: std.AutoHashMap(u64, void),
+
pub const OnUnhandledRejection = fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void;
pub const OnException = fn (*ZigException) void;
@@ -1068,6 +1070,7 @@ pub const VirtualMachine = struct {
.file_blobs = JSC.WebCore.Blob.Store.Map.init(allocator),
.standalone_module_graph = opts.graph.?,
.parser_arena = @import("root").bun.ArenaAllocator.init(allocator),
+ .registered_one_shot_epoll_fds = std.AutoHashMap(u64, void).init(allocator),
};
vm.source_mappings = .{ .map = &vm.saved_source_map_table };
vm.regular_event_loop.tasks = EventLoop.Queue.init(
@@ -1170,6 +1173,7 @@ pub const VirtualMachine = struct {
.ref_strings_mutex = Lock.init(),
.file_blobs = JSC.WebCore.Blob.Store.Map.init(allocator),
.parser_arena = @import("root").bun.ArenaAllocator.init(allocator),
+ .registered_one_shot_epoll_fds = std.AutoHashMap(u64, void).init(allocator),
};
vm.source_mappings = .{ .map = &vm.saved_source_map_table };
vm.regular_event_loop.tasks = EventLoop.Queue.init(
@@ -1301,6 +1305,7 @@ pub const VirtualMachine = struct {
.parser_arena = @import("root").bun.ArenaAllocator.init(allocator),
.standalone_module_graph = worker.parent.standalone_module_graph,
.worker = worker,
+ .registered_one_shot_epoll_fds = std.AutoHashMap(u64, void).init(allocator),
};
vm.source_mappings = .{ .map = &vm.saved_source_map_table };
vm.regular_event_loop.tasks = EventLoop.Queue.init(
@@ -1922,6 +1927,7 @@ pub const VirtualMachine = struct {
// TODO:
pub fn deinit(this: *VirtualMachine) void {
this.source_mappings.deinit();
+ this.registered_one_shot_epoll_fds.deinit();
}
pub const ExceptionList = std.ArrayList(Api.JsException);