Skip to content

Commit 1312069

Browse files
authored
fix: deadlock in resource distributor (#1197)
1 parent 1b1b2b2 commit 1312069

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

1010
## [11.2.1]
1111

12+
- Fixes deadlock issue with `ResourceDistributor`
1213
- Fixes race issues with Refreshing OAuth token
1314

1415
## [11.2.0]

src/main/java/io/supertokens/ResourceDistributor.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public static TenantIdentifier getAppForTesting() {
5151
return appUsedForTesting;
5252
}
5353

54-
public synchronized SingletonResource getResource(AppIdentifier appIdentifier, @Nonnull String key)
54+
public SingletonResource getResource(AppIdentifier appIdentifier, @Nonnull String key)
5555
throws TenantOrAppNotFoundException {
5656
return getResource(appIdentifier.getAsPublicTenantIdentifier(), key);
5757
}
5858

59-
public synchronized SingletonResource getResource(TenantIdentifier tenantIdentifier, @Nonnull String key)
59+
public SingletonResource getResource(TenantIdentifier tenantIdentifier, @Nonnull String key)
6060
throws TenantOrAppNotFoundException {
6161
// first we do exact match
6262
SingletonResource resource = resources.get(new KeyClass(tenantIdentifier, key));
@@ -70,14 +70,6 @@ public synchronized SingletonResource getResource(TenantIdentifier tenantIdentif
7070
throw new TenantOrAppNotFoundException(tenantIdentifier);
7171
}
7272

73-
MultitenancyHelper.getInstance(main).refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged(true);
74-
75-
// we try again..
76-
resource = resources.get(new KeyClass(tenantIdentifier, key));
77-
if (resource != null) {
78-
return resource;
79-
}
80-
8173
// then we see if the user has configured anything to do with connectionUriDomain, and if they have,
8274
// then we must return null cause the user has not specifically added tenantId to it
8375
for (KeyClass currKey : resources.keySet()) {
@@ -101,11 +93,11 @@ public synchronized SingletonResource getResource(TenantIdentifier tenantIdentif
10193
}
10294

10395
@TestOnly
104-
public synchronized SingletonResource getResource(@Nonnull String key) {
96+
public SingletonResource getResource(@Nonnull String key) {
10597
return resources.get(new KeyClass(appUsedForTesting, key));
10698
}
10799

108-
public synchronized SingletonResource setResource(TenantIdentifier tenantIdentifier,
100+
public SingletonResource setResource(TenantIdentifier tenantIdentifier,
109101
@Nonnull String key,
110102
SingletonResource resource) {
111103
SingletonResource alreadyExists = resources.get(new KeyClass(tenantIdentifier, key));
@@ -116,7 +108,7 @@ public synchronized SingletonResource setResource(TenantIdentifier tenantIdentif
116108
return resource;
117109
}
118110

119-
public synchronized SingletonResource removeResource(TenantIdentifier tenantIdentifier,
111+
public SingletonResource removeResource(TenantIdentifier tenantIdentifier,
120112
@Nonnull String key) {
121113
SingletonResource singletonResource = resources.get(new KeyClass(tenantIdentifier, key));
122114
if (singletonResource == null) {
@@ -126,18 +118,18 @@ public synchronized SingletonResource removeResource(TenantIdentifier tenantIden
126118
return singletonResource;
127119
}
128120

129-
public synchronized SingletonResource setResource(AppIdentifier appIdentifier,
121+
public SingletonResource setResource(AppIdentifier appIdentifier,
130122
@Nonnull String key,
131123
SingletonResource resource) {
132124
return setResource(appIdentifier.getAsPublicTenantIdentifier(), key, resource);
133125
}
134126

135-
public synchronized SingletonResource removeResource(AppIdentifier appIdentifier,
127+
public SingletonResource removeResource(AppIdentifier appIdentifier,
136128
@Nonnull String key) {
137129
return removeResource(appIdentifier.getAsPublicTenantIdentifier(), key);
138130
}
139131

140-
public synchronized void clearAllResourcesWithResourceKey(String inputKey) {
132+
public void clearAllResourcesWithResourceKey(String inputKey) {
141133
List<KeyClass> toRemove = new ArrayList<>();
142134
resources.forEach((key, value) -> {
143135
if (key.key.equals(inputKey)) {
@@ -149,7 +141,7 @@ public synchronized void clearAllResourcesWithResourceKey(String inputKey) {
149141
}
150142
}
151143

152-
public synchronized Map<KeyClass, SingletonResource> getAllResourcesWithResourceKey(String inputKey) {
144+
public Map<KeyClass, SingletonResource> getAllResourcesWithResourceKey(String inputKey) {
153145
Map<KeyClass, SingletonResource> result = new HashMap<>();
154146
resources.forEach((key, value) -> {
155147
if (key.key.equals(inputKey)) {
@@ -160,7 +152,7 @@ public synchronized Map<KeyClass, SingletonResource> getAllResourcesWithResource
160152
}
161153

162154
@TestOnly
163-
public synchronized SingletonResource setResource(@Nonnull String key,
155+
public SingletonResource setResource(@Nonnull String key,
164156
SingletonResource resource) {
165157
return setResource(appUsedForTesting, key, resource);
166158
}

0 commit comments

Comments
 (0)