Skip to content

Commit 5b62ade

Browse files
committed
WIP - thread safety fixes
1 parent b0d4a71 commit 5b62ade

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/java/picoded/dstack/stack/ProviderConfig.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public class ProviderConfig {
5353
**/
5454
public ProviderConfig(List<Object> inConfigList) {
5555
System.out.println("!! Setting up ProviderConfig");
56+
57+
// The variables are intentionally initialized here inside the constructor
58+
providerConfigMap = new HashMap<>();
59+
providerStackMap = new ConcurrentHashMap<>();
60+
5661
loadConfigArray(inConfigList);
5762
}
5863

@@ -65,7 +70,7 @@ public ProviderConfig(List<Object> inConfigList) {
6570
/**
6671
* Stores the internal config mapping by its name
6772
**/
68-
protected final Map<String, GenericConvertMap<String, Object>> providerConfigMap = new HashMap<>();;
73+
protected final Map<String, GenericConvertMap<String, Object>> providerConfigMap;
6974

7075
/**
7176
* Loads a configuration array of backend providers for dstack, into the provider map
@@ -118,7 +123,7 @@ protected GenericConvertMap<String, Object> getStackConfig(String name) {
118123
/**
119124
* Stores the respective stack providers
120125
*/
121-
protected volatile ConcurrentHashMap<String, CoreStack> providerStackMap = new ConcurrentHashMap<>();
126+
protected final ConcurrentHashMap<String, CoreStack> providerStackMap;
122127

123128
/**
124129
* Get the stack of the provider specified by the name,
@@ -135,7 +140,7 @@ public CoreStack getProviderStack(String name) {
135140
return cache;
136141
}
137142

138-
synchronized (providerStackMap) {
143+
synchronized (this) {
139144
// Check the cache again (avoid race condition)
140145
cache = providerStackMap.get(name);
141146
if (cache != null) {

0 commit comments

Comments
 (0)