Skip to content

fix(bbb-graphql-server): lower connection_lifetime to limit Postgres memory growth - #25310

Merged
TiagoJacobs merged 1 commit into
bigbluebutton:v3.0.x-developfrom
imdt-claudiop:bbb-graphql-connection-lifetime
Jun 23, 2026
Merged

TiagoJacobs merged 1 commit into
bigbluebutton:v3.0.x-developfrom
imdt-claudiop:bbb-graphql-connection-lifetime

Conversation

@imdt-claudiop

@imdt-claudiop imdt-claudiop commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The BigBlueButton source in bbb-graphql-server/metadata/databases/databases.yaml keeps each Postgres connection alive for 1 hour (connection_lifetime: 3600). This lowers it to 300 (5 minutes) - the value tested in the investigation.

It is a one-line change, but it fixes a real memory problem, shown in the charts below.

The problem

On busy BBB 3.x servers, Postgres memory grows through the day and never comes back down, even when load drops. Over a workday this pushes servers into swap, and the visible result is audio joins timing out during the busiest hours.

A snapshot of 5 production hosts:

Host Connections Postgres memory idle (graphql pool) Per-connection memory idle-in-transaction
A 72 6.74 GB 59 100-200 MB 0
B 78 8.06 GB 64 100-200 MB 0
C 79 7.95 GB 65 100-200 MB 0
D 108 7.87 GB 94 60-100 MB 0
E 84 5.17 GB 72 60-100 MB 0

Almost every connection belongs to the BBB graphql server's pool, sits idle, and was used less than a minute ago. The last column matters: idle-in-transaction is 0 on every host, which rules out the most common fix people try first.

Why it happens

The BBB graphql server keeps a pool of Postgres connections and reuses them. While a connection stays open, Postgres holds onto the memory it used to run queries and does not give it back to the system. The only thing that frees that memory is closing the connection.

The pool closes a connection after it has been idle for 180 seconds, or after it has lived for connection_lifetime. During a busy day the pool is never idle for 180 seconds (the graphql server queries it constantly), so the only thing recycling connections is connection_lifetime: 3600 - one full hour. With up to 100 connections each holding memory for an hour, several GB pile up and never get returned.

Each line below is one connection. Its memory only goes up, never down, for as long as it lives:

Per-connection memory over time, stock config - it only goes up

Why the usual fixes don't work

  • idle_in_transaction_session_timeout - there are no idle-in-transaction connections (the pool is plain idle), so there is nothing for it to act on.
  • idle_session_timeout - Postgres resets this timer on every query. The graphql server queries the pool constantly, so no connection is ever idle long enough for it to fire. Tested at 300s: no effect.

There is also a trap that hides the bug in tests: if a test pauses longer than 180 seconds between bursts of activity, the pool drains on its own and memory snaps back, so the server looks healthy. Production never pauses that long, so the problem only shows up there.

The fix

Lower connection_lifetime from 3600 to 300. Connections now close and reopen every 5 minutes while still under load, so the memory they held is freed before it can pile up.

Same workload, stock config vs the fix:

Total Postgres memory over time: stock (3600s) vs fix (300s)

  • Stock (3600s): the memory held between bursts only climbs (750 -> 882 MB) until the 1-hour lifetime finally starts closing the oldest connections.
  • Fix (300s): the memory held between bursts falls (761 -> 676 MB) under the same load.

The effect is clearest here - each dot is one connection sampled every 20 seconds, age vs memory:

Each connection's age vs memory: stock vs fix

Stock drifts to the top-right (older connections holding more memory); the fix keeps both age and memory small.

Cost

One reconnect per connection every 5 minutes. The graphql server already queries each connection constantly, so this is negligible.

Rollout

Test on one host first with connection_lifetime: 300 and confirm: Postgres memory stays bounded across a full workday, the bbb-graphql-server logs show no connection errors, and client graphql_client_error rates are unchanged.

Draft - opening for early review.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fdc55c96-56f2-4b49-b274-279916145bc8

📥 Commits

Reviewing files that changed from the base of the PR and between de8bd4a and 87e9019.

📒 Files selected for processing (1)
  • bbb-graphql-server/metadata/databases/databases.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • bbb-graphql-server/metadata/databases/databases.yaml

Walkthrough

In bbb-graphql-server/metadata/databases/databases.yaml, the pool_settings.connection_lifetime value for the BigBlueButton PostgreSQL database connection pool was decreased from 3600 seconds (1 hour) to 300 seconds (5 minutes).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change: reducing the connection_lifetime setting to address Postgres memory growth issues.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the problem, root cause, solution, evidence, and testing recommendations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@imdt-claudiop
imdt-claudiop force-pushed the bbb-graphql-connection-lifetime branch from a7af081 to de8bd4a Compare June 23, 2026 00:32
@TiagoJacobs
TiagoJacobs marked this pull request as ready for review June 23, 2026 00:35
…memory growth

The BigBlueButton source in bbb-graphql-server metadata keeps each
Postgres connection alive for 1 hour (connection_lifetime: 3600). While a
connection stays open, Postgres holds onto the memory it used and never
returns it to the system, so a 1-hour lifetime with up to 100 connections
lets several GB pile up across a workday and pushes hosts into swap.

Lowering it to 300 (the value validated in the investigation) recycles
connections while still under load, so per-connection memory stays
bounded. The cost is one reconnect per connection every 5 minutes,
negligible next to the graphql server's constant query polling.

Co-Authored-By: Tiago Jacobs <[email protected]>
@imdt-claudiop imdt-claudiop changed the title Lower connection_lifetime for BigBlueButton graphql source fix(bbb-graphql-server): lower connection_lifetime to limit Postgres memory growth Jun 23, 2026
@imdt-claudiop
imdt-claudiop force-pushed the bbb-graphql-connection-lifetime branch from de8bd4a to 87e9019 Compare June 23, 2026 00:37
@TiagoJacobs
TiagoJacobs merged commit ab7b61f into bigbluebutton:v3.0.x-develop Jun 23, 2026
21 of 22 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

🚨 Automated tests failed

@antobinary antobinary added this to the Release 3.0 milestone Jul 6, 2026
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.

3 participants