mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
dispatchWithCooldownRetry arms a loop-safety timer (setTimeout, 10 minutes by default) on every setTry iteration, so a combo that never produces a terminal response still answers with a 504 instead of hanging. The only clearTimeout in the whole file sat inside the `if (anySuccess)` branch — the comment said so verbatim: "clear the safety timer on the happy path". Every error exit therefore returned the response to the client while leaving a 600s timer pending, its closure retaining orderedTargets and the exhausted provider/connection sets: all_targets_skipped, all_accounts_inactive, the aggregated-status return, the final fallback, and the global-timeout branch. The timer is also re-armed per setTry iteration with no clear in between. Field evidence from the issue: two requests that failed quality validation returned 502 to the client immediately, and "Combo loop safety timeout ... force-terminating" was logged for both exactly 600 seconds later — the leaked timers firing long after the requests were gone. Fixed structurally rather than by sprinkling clearTimeout across the five return sites: the handle is hoisted to function scope and released in a finally, so a future `return` added to this function cannot silently reintroduce the leak. The 504 backstop itself is unchanged. Note the timer already called .unref(), so it never held the event loop open — this is a memory-retention leak, not a hang.