Skip to content

fix: test and fix how we handle the POSTGRESQL_MINIMUM_IDLE_CONNECTIONS envvar#303

Merged
tamassoltesz merged 3 commits into
9.4from
fix/min_idle_connection_envvar
Mar 18, 2026
Merged

fix: test and fix how we handle the POSTGRESQL_MINIMUM_IDLE_CONNECTIONS envvar#303
tamassoltesz merged 3 commits into
9.4from
fix/min_idle_connection_envvar

Conversation

@porcellus

Copy link
Copy Markdown
Collaborator

Summary of change

(A few sentences about this PR)

Related issues

  • Link to issue1 here
  • Link to issue1 here

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your
changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here
highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • pluginInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In build.gradle
  • Had installed and ran the pre-commit hook
  • If there are new dependencies that have been added in build.gradle, please make sure to add them
    in implementationDependencies.json.
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the
      latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • When adding new recipes, ensure that its performance is being measured in the OneMillionUsersTest

Remaining TODOs for this PR

  • Item1
  • Item2

@tamassoltesz tamassoltesz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. Changelog and build version?

return Config.canBeUsed(configJson);
}

@Override

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an Override. Does this method have any other implementation that's affected?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yup, but it's in Core so I wanted to validate this first.

Comment on lines +30 to +42
private static void setEnv(String key, String value) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.put(key, value);
} catch (Exception e) {
throw new IllegalStateException("Failed to set environment variable", e);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The test relies on accessing an internal field named "m" in the System.getenv() implementation. This field name is specific to certain JVM implementations and is not guaranteed across all Java versions or implementations. The test will fail at runtime on JVMs where the environment map implementation uses a different field name.

// This assumes the internal field is named "m"
Field field = cl.getDeclaredField("m");

Consider using a more portable approach for testing environment variable handling, such as:

  • Using a dependency injection pattern to inject the config source
  • Using system properties instead of environment variables for testing
  • Using a library like System Rules or System Lambda that provides safer environment variable mocking
Suggested change
private static void setEnv(String key, String value) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.put(key, value);
} catch (Exception e) {
throw new IllegalStateException("Failed to set environment variable", e);
}
}
private static void setEnv(String key, String value) {
// Use system properties instead of environment variables for testing
// This is more portable and doesn't rely on JVM implementation details
System.setProperty(key, value);
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tamassoltesz tamassoltesz merged commit 7ecc942 into 9.4 Mar 18, 2026
3 of 4 checks passed
@tamassoltesz tamassoltesz deleted the fix/min_idle_connection_envvar branch March 18, 2026 11:53
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.

2 participants