Skip to content

Commit c8fac51

Browse files
diogo24mjmmoser
authored andcommitted
Fix internalDestroy causing node crash
When the ForwardClose times out, CIPConnectionLayer.js calls this.destroy('Forward Close error'). That goes into internalDestroy, which iterates pending callbacks. One of them is the very same disconnect callback. Inside that callback, this.destroy(...) is called again, and because clear() happens after forEach, the map still contains the same callback, so it re-enters infinitely. internalDestroy now clears the callback map before invoking, breaking the recursion.
1 parent 808713b commit c8fac51

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/layers/Layer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ function internalDestroy(layer, error) {
2424
layer.__contextToCallbackTimeouts.forEach((handle) => clearTimeout(handle));
2525
layer.__contextToCallbackTimeouts.clear(); // eslint-disable-line no-underscore-dangle
2626

27-
layer.__contextToCallback.forEach((cb) => cb(error)); // eslint-disable-line no-underscore-dangle
27+
const callbacks = Array.from(layer.__contextToCallback.values());
2828
layer.__contextToCallback.clear(); // eslint-disable-line no-underscore-dangle
29+
for (const cb of callbacks) {
30+
try { cb(error); } catch (e) { /* swallow — destroy must not throw */ }
31+
}
2932

3033
layer.__idContext.clear(); // eslint-disable-line
3134

0 commit comments

Comments
 (0)