There is a memory leak in the _sendAug function in shardus-net (TypeScript side).
When timeout === 0 (meaning "no response expected" / fire-and-forget), the function still creates a 5-minute setTimeout that is never cleared.
Code Location
} else {
const timer = setTimeout(() => {
resolve({ success: false, error: 'Request timed out 2' })
}, 300 * 1000) // 5 minutes
}
Root Cause
- A
setTimeout is created but the returned timer ID is not stored.
- No
clearTimeout() is ever called for this case.
- The callback closes over
resolve, augData, and other variables.
- These timers accumulate over time, especially under high message throughput.
Impact
- Gradual memory growth over time.
- Increased GC pressure.
- Potential Out-of-Memory crashes in long-running nodes.
- Worse under high load (common in shardus-core multi-send scenarios).
Suggested Fix
- When
timeout === 0, do not create any timeout (true fire-and-forget).
- Or, if a safety timeout is desired, store the timer ID and ensure it gets cleared when the send completes.
- Consistently store and clear all timers in the success path.
Example of clean handling:
if (timeout !== 0) {
const timer = setTimeout(...);
responseUUIDMapping[augData.UUID] = {
callback: (...) => {
clearTimeout(timer);
onResponse(...);
}
};
}
// else → no timer created
Additional Notes
- The comment says:
"a timeout of 0 means no return message is expected." — the code should respect this.
- This affects both single and multi-send paths using
_sendAug.
There is a memory leak in the
_sendAugfunction inshardus-net(TypeScript side).When
timeout === 0(meaning "no response expected" / fire-and-forget), the function still creates a 5-minutesetTimeoutthat is never cleared.Code Location
Root Cause
setTimeoutis created but the returned timer ID is not stored.clearTimeout()is ever called for this case.resolve,augData, and other variables.Impact
Suggested Fix
timeout === 0, do not create any timeout (true fire-and-forget).Example of clean handling:
Additional Notes
"a timeout of 0 means no return message is expected."— the code should respect this._sendAug.