Skip to content

Commit

Permalink
fix: connection pool issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Feb 6, 2024
1 parent a7ccacb commit 065bf5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Fixes issue where error logs were printed to StdOut instead of StdErr.
- Adds new config `supertokens_saas_load_only_cud` that makes the core instance load a particular CUD only, irrespective of the CUDs present in the db.
- Fixes connection pool handling when connection pool size changes for a tenant.

## [7.0.16] - 2023-12-04

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/io/supertokens/storageLayer/StorageLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static void loadAllTenantStorage(Main main, TenantConfig[] tenants)
}
main.getResourceDistributor().clearAllResourcesWithResourceKey(RESOURCE_KEY);

Set<String> userPoolsInUse = new HashSet<>();
Set<String> uniquePoolsInUse = new HashSet<>();

for (ResourceDistributor.KeyClass key : resourceKeyToStorageMap.keySet()) {
Storage currStorage = resourceKeyToStorageMap.get(key);
Expand All @@ -259,11 +259,16 @@ public static void loadAllTenantStorage(Main main, TenantConfig[] tenants)
main.getResourceDistributor().setResource(key.getTenantIdentifier(), RESOURCE_KEY,
new StorageLayer(resourceKeyToStorageMap.get(key)));

userPoolsInUse.add(userPoolId);
uniquePoolsInUse.add(uniqueId);
}

for (ResourceDistributor.KeyClass key : existingStorageMap.keySet()) {
if (!userPoolsInUse.contains(((StorageLayer) existingStorageMap.get(key)).storage.getUserPoolId())) {
Storage existingStorage = ((StorageLayer) existingStorageMap.get(key)).storage;
String userPoolId = existingStorage.getUserPoolId();
String connectionPoolId = existingStorage.getConnectionPoolId();
String uniqueId = userPoolId + "~" + connectionPoolId;

if (!uniquePoolsInUse.contains(uniqueId)) {
((StorageLayer) existingStorageMap.get(key)).storage.close();
((StorageLayer) existingStorageMap.get(key)).storage.stopLogging();
}
Expand Down

0 comments on commit 065bf5b

Please sign in to comment.