Skip to main content

What it flags

.on(), .addListener(), or .addEventListener() is registered in a request handler, loop, or lifecycle hook without cleanup. For example, calling sharedSocket.on('close', handler) on every iteration accumulates handlers on the same socket. The rule recognizes cases where each iteration creates its own Node.js socket. It also recognizes a registry’s bulk registration method forwarding caller-supplied listeners to its own registration method with a corresponding removal API. For a Node.js file read stream created inside a request handler, the rule recognizes a preceding request or response close callback or a request aborted callback that destroys the same stream. This requires a local stream that stays inside the handler. For DOM elements, a render function can map its data to elements it creates with document.createElement and then give each element one listener in a single loop. The rule accepts that when the list is only iterated afterwards. Elements from a shared list, a list that is also modified, or a loop nested in another loop keep their finding. Streams returned by other factories are not assumed to be fresh.

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: