Openbravo Issue Tracking System - Retail Modules
View Issue Details
0033409Retail ModulesStoreServerpublic2016-07-01 12:252017-02-07 17:53
mtaal 
AugustoMauch 
normalminorhave not tried
closedduplicate 
5
 
 
No
0033409: Prevent race condition & improve initialization code in Mobile Server Key by org/client cache
The current code which initializes the cache of mobile server keys by org/client cache has a danger of a race condition as it sets the mobileServersByClient member in the beginning of the initialization code. This means that any next call to getNodeIdsForClient will continue and possibly access a not-yet-initialized mobileServersByClient.

https://code.openbravo.com/erp/pmods/org.openbravo.replication.symmetricds/file/5ff67cc8ae3b/src/org/openbravo/replication/symmetricds/util/MobileServerProvider.java#l102 [^]

Also it seems that the initialization code of the mobileServersByClient again calls getMobileServersByClient. This is not adviced in these type of initialization code.
See the code
To initialize a cache in safe way a code structure like this below can be used.


private Map<String, String> cache = null;


public Map<String, String> getCache() {
  if (cache == null) {
   initializeCache();
  }
  return cache;
}

private synchronized initializeCache() {
  if (cache != null) {
   return;
  }
  final Map<String, String> localCache = new HashMap...;
  // initialize the localCache, try not to call to many
  // other methods, makes it confusing, make sure that any other methods
  // you use here to initialize do not use/call getCache()

  // initialization done, set, this is threadsafe
  cache = localCache;
}
No tags attached.
duplicate of feature request 0034999RR17Q2 closed mtaal Do more caching and re-organize code in MobileServerProvider in the Replication Module 
Issue History
2016-07-01 12:25mtaalNew Issue
2016-07-01 12:25mtaalAssigned To => AugustoMauch
2016-07-11 13:17gorka_gilProjectModules => Retail Modules
2016-07-11 13:23gorka_gilCategoryStoreServer Configuration => (No Category)
2016-07-11 13:26gorka_gilCategory(No Category) => StoreServer Configuration
2016-07-12 16:12mtaalTriggers an Emergency Pack => No
2016-07-12 16:12mtaalCategoryStoreServer Configuration => StoreServer Infrastructure
2016-07-12 16:13gorka_gilCategoryStoreServer Infrastructure => StoreServer
2017-02-07 17:53AugustoMauchRelationship addedduplicate of 0034999
2017-02-07 17:53AugustoMauchStatusnew => closed
2017-02-07 17:53AugustoMauchResolutionopen => duplicate

There are no notes attached to this issue.