Skip to content

Fix memory leaks and race conditions from improper timeout management#2951

Merged
saghul merged 2 commits intojitsi:masterfrom
4rayaditya:fix-timeout-memory-leaks
Dec 10, 2025
Merged

Fix memory leaks and race conditions from improper timeout management#2951
saghul merged 2 commits intojitsi:masterfrom
4rayaditya:fix-timeout-memory-leaks

Conversation

@4rayaditya
Copy link
Contributor

  • Fix critical 5-second timeout leak in ChatRoom.leave() where timeout was never cleared when MUC_LEFT fired successfully
  • Add comprehensive dispose() method to QualityController to clear all active timeouts (_timer, _limitedByCpuTimeout, _lastNRampupTimeout)
  • Fix orphaned 5-second keepalive timeout in XmppConnection by storing timeout reference
  • Add QualityController disposal to JitsiConference.leave() lifecycle
  • Prevent zombie timers, memory leaks, and race conditions in long-running conferences

Fixes #2949

- Fix critical 5-second timeout leak in ChatRoom.leave() where timeout was never cleared when MUC_LEFT fired successfully
- Add comprehensive dispose() method to QualityController to clear all active timeouts (_timer, _limitedByCpuTimeout, _lastNRampupTimeout)
- Fix orphaned 5-second keepalive timeout in XmppConnection by storing timeout reference
- Add QualityController disposal to JitsiConference.leave() lifecycle
- Prevent zombie timers, memory leaks, and race conditions in long-running conferences

Fixes jitsi#2949
@jitsi-jenkins
Copy link

Hi, thanks for your contribution!
If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

clearTimeout(timeout as number);

// Always clear the timeout to prevent memory leaks and race conditions
if (timeout !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this, this part was working ok before, clearTimeout is resilient to bad input.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I have removed the changes.

// and to allow backend to correct any possible split brain issues
setTimeout(() => this._keepAliveAndCheckShard(), 5000);
// Store timeout so it can be cleared if needed
this._wsKeepAlive = setTimeout(() => this._keepAliveAndCheckShard(), 5000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you clrearing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are 3 instances -

  1. around line 423 - When the status becomes DISCONNECTED, it calls clearTimeout(this._wsKeepAlive) to clean up before attempting to resume the connection.

  2. line 469 - The code clears the timeout as part of disconnecting the XMPP connection.

  3. around line 537 - _maybeStartWSKeepAlive clears any existing timeout before scheduling a new keep-alive interval.

}

if (this.qualityController) {
this.qualityController.dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@4rayaditya
Copy link
Contributor Author

@saghul I have done the necessary changes. Could you check it again?

@saghul
Copy link
Member

saghul commented Dec 10, 2025

Jenkins please test this please.

@saghul saghul merged commit ef10c01 into jitsi:master Dec 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Memory leaks and race conditions from improper timeout management in QualityController, and BridgeChannel

3 participants