一句话:提出 NodeRT,通过异步调用树与三阶段动态检测,高效发现 Node.js 事件处理竞态并降低误报。
Node.js 因其并发支持而广泛使用,但事件处理器执行顺序不确定会导致竞态,引发运行时故障。现有 NRace 先构建 happens-before 图,再用重量级 BFS 查询资源操作可达性,开销过大,难以适用于真实测试流程。本文提出更实用的 Node.js 动态竞态检测方法 NodeRT,将检测分为轨迹收集、竞态候选检测和误报消除三阶段。轨迹收集阶段构建部分 HB 图,称为异步调用树 ACTree,以高效查询事件处理器间可达性;候选检测阶段在 ACTree 上排除多数非竞态事件处理器;误报消除阶段利用由 HB 规则和资源特征导出的匹配规则过滤误报。实验表明,NodeRT 检出真实应用中全部已知竞态和 9 个未知有害竞态,而 NRace 仅检出其中 3 个,且 NodeRT 平均耗时少 64 倍,显著降低开销,便于集成到实际测试流程。
Node.js has become one of the most popular development platforms due to its superior concurrency support. However, races induced by the nondeterministic execution order of event handlers may occur in Node.js applications, causing serious runtime failures. The state-of-the-art Node.js race detector NRace builds a happens-before (HB) graph before detection with a set of HB relation rules. In detection, NRace utilizes a heavy-weight BFS-based algorithm to query the reachability between resource operations, which introduces substantial overhead in practice, causing NRace inapplicable to real-world Node.js application test processes. This paper proposes a more practical Node.js dynamic race detection approach called NodeRT (Node.js Race Tracker). To reduce unnecessary overhead, NodeRT simplifies the HB relation rules, and divides the detection into three stages: trace collection stage, race candidate detection stage, and false positive removal stage. In the trace collection stage, NodeRT constructs a partial HB graph called asynchronous call tree (ACTree), enabling efficient reachability queries between event handlers. In the race candidate detection stage, NodeRT performs detection on the ACTree, which effectively eliminates most non-racing event handlers and outputs race candidates. In the false positive removal stage, NodeRT utilizes matching rules derived from HB relation rules and features of resources to reduce false positives in the race candidates. In experiments, NodeRT detects all known races and 9 unknown harmful races in real-world applications, whereas NRace only detects 3 of the unknown harmful races, with 64× more time consumption on average. Compared with NRace, NodeRT significantly reduces the overhead, making it practical to be integrated into real-world test processes.