Skip to content

Conversation

@amirparsadd
Copy link

@amirparsadd amirparsadd commented Nov 20, 2025

📋 Overview

I saw an issue saying that mariadb max connections should be controllable through env variables so this PR fixes that with a new env variable:

  • MARIADB_POOL_MAX_CONNECTIONS

🛠️ Type of change

  • 🐛 Bugfix (a non-breaking change that resolves an issue)
  • ✨ New feature (a non-breaking change that adds new functionality)
  • ⚠️ Breaking change (a fix or feature that alters existing functionality in a way that could cause issues)
  • 🎨 User Interface (UI) updates
  • 📄 New Documentation (addition of new documentation)
  • 📄 Documentation Update (modification of existing documentation)
  • 📄 Documentation Update Required (the change requires updates to related documentation)
  • 🔧 Other (please specify):
    • Provide additional details here.

📄 Checklist

  • 🔍 My code adheres to the style guidelines of this project.
  • 🦿 I have indicated where (if any) I used an LLM for the contributions
  • ✅ I ran ESLint and other code linters for modified files.
  • 🛠️ I have reviewed and tested my code.
  • 📝 I have commented my code, especially in hard-to-understand areas (e.g., using JSDoc for methods).
  • ⚠️ My changes generate no new warnings.
  • 🤖 My code needed automated testing. I have added them (this is an optional task).
  • 📄 Documentation updates are included (if applicable).
  • 🔒 I have considered potential security impacts and mitigated risks.
  • 🧰 Dependency updates are listed and explained.
  • 📚 I have read and understood the Pull Request guidelines.

📷 Screenshots or Visual Changes

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

Could you please make sure that all environment variables stick to our existing naming scheme

https://github.com/louislam/uptime-kuma/wiki/Environment-Variables#mariadb-environment-variables

I am also not entirely sure if the min pool size should be configurable. What is the effect there?

@amirparsadd
Copy link
Author

Could you please make sure that all environment variables stick to our existing naming scheme

https://github.com/louislam/uptime-kuma/wiki/Environment-Variables#mariadb-environment-variables

I am also not entirely sure if the min pool size should be configurable. What is the effect there?

It's now following standards and i removed the min connections env

@louislam
Copy link
Owner

I think it needs some validations. Like checking a empty string, NaN etc. Or maybe number range.

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks 🙏
Should be uncontroversial and help the few people on a limited pool Mariadb hoster

@CommanderStorm CommanderStorm added this to the 2.1.0 milestone Nov 21, 2025
@CommanderStorm CommanderStorm enabled auto-merge (squash) November 21, 2025 11:04
auto-merge was automatically disabled November 21, 2025 11:25

Head branch was pushed to by a user without write access

@amirparsadd
Copy link
Author

@CommanderStorm i added validation as Louis said

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

Please polish your code one round.

Please instead default to 10 and then add an if statement if the env var contains a valid number.
Number.MAX_SAFE_INTEGER for example is not a sensible max.

Also please log if a value does not get applied.

@louislam
Copy link
Owner

Plus, you don't need to call parseInt 4 times.

@CommanderStorm CommanderStorm changed the title make mariadb pool connections controllable through env variables feat: make mariadb max pool connections controllable through env variables Nov 23, 2025
@CommanderStorm CommanderStorm changed the title feat: make mariadb max pool connections controllable through env variables feat: make mariadb max pool connections controllable via env Nov 23, 2025
@amirparsadd
Copy link
Author

Changes:

  • added reasonable max
  • added logging on fail
  • removed repetitive parseInt

@amirparsadd
Copy link
Author

@CommanderStorm This is ready

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

The code isn’t yet at a level where I can merge it.
I’ve given more detailed feedback this time - please incorporate those changes, and then we can move forward.

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

I still think that the code quality does not 100% meet what I would like the code to be in terms of readability.

What do you think of my variant of writing ths

Comment on lines +226 to +242
let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);
let error = undefined;

if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS || Number.isNaN(parsedMaxPoolConnections)) {
error = "invalid";
} else if (parsedMaxPoolConnections < 1) {
error = "less than 1";
} else if (parsedMaxPoolConnections > 100) {
error = "more than 100";
log.warn("db", "We cap pool connections because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
}

if (error) {
log.warn("db", `Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was ${error}.`);
} else {
log.info("db", `Max database connections: ${parsedMaxPoolConnections}`);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your switching on error way of writing this is fairly hard to read.
Lets simplify

Suggested change
let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);
let error = undefined;
if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS || Number.isNaN(parsedMaxPoolConnections)) {
error = "invalid";
} else if (parsedMaxPoolConnections < 1) {
error = "less than 1";
} else if (parsedMaxPoolConnections > 100) {
error = "more than 100";
log.warn("db", "We cap pool connections because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
}
if (error) {
log.warn("db", `Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was ${error}.`);
} else {
log.info("db", `Max database connections: ${parsedMaxPoolConnections}`);
}
let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);
if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS) {
parsedMaxPoolConnections = 10;
} else if (Number.isNaN(parsedMaxPoolConnections)) {
log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid.");
parsedMaxPoolConnections = 10;
} else if (parsedMaxPoolConnections < 1) {
log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was less than 1.");
parsedMaxPoolConnections = 10;
} else if (parsedMaxPoolConnections > 100) {
log.warn("db", "Max database connections capped to 100 because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
parsedMaxPoolConnections = 100;
}

let mariadbPoolConfig = {
min: 0,
max: 10,
max: error ? 10 : parsedMaxPoolConnections,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
max: error ? 10 : parsedMaxPoolConnections,
max: parsedMaxPoolConnections,

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.

Configurable maximum parallel MariaDB connections

3 participants