Hide Forgot
Description of problem: Assuming you configure KnowledgeAgent/ResourceChangeScanner with ChangeSet.xml to connect to Guvnor. In addition, you configure drools.resource.urlcache to enable local file cache. The following sequence happens when ResourceChangeScanner detects package update: (A) UrlResource.getInputStream() reads the package from Guvnor and persist it as a local file cache. (B) UrlResource.getInputStream() returns the package from Guvnor again and return the InputStream to KnowledgeAgent. public InputStream getInputStream() throws IOException { try { long lastMod = grabLastMod(); if (lastMod == 0) { //we will try the cache... if (cacheFileExists()) return fromCache(); } if (lastMod > 0 && lastMod > lastRead) { if (CACHE_DIR != null && url.getProtocol().equals("http") || url.getProtocol().equals("https")) { //lets grab a copy and cache it in case we need it in future... (A)==> cacheStream(); lastMod = getCacheFile().lastModified(); // added by BZ1027221 } } this.lastRead = lastMod; (B)==> return grabStream(); } catch (IOException e) { if (cacheFileExists()) { return fromCache(); } else { throw e; } } } If the package is updated again in Guvnor between (A) and (B), the local file cache stores the stale package version. It will be an issue when Guvnor goes down and the client reboots (= will use the local file cache). Steps to Reproduce: 1. Use latest 5.3.x drools-core (includes BZ917787, BZ1027216, BZ1027221, BZ1034030) 2. Set a breakpoint in UrlResource.getInputStream() before "return grabStream();" in client. 3. Start Guvnor 4. Start a client 5. Update an asset and build a package in Guvnor (= pkg_ver2) 6. After stopping at the breakpoint, update an asset and build a package in Guvnor again (= pkg_ver3) 7. Resume the debugger (Now, memory = pkg_ver3 , local cache file = pkg_ver2) 8. Rules will run with pkg_ver3 9. Shutdown Guvnor 10. Reboot the client (will read the local cache file) 11. Rules will run with pkg_ver2 until it gets updated by KnowlegeAgent+Guvnor Actual results: The problem is the mismatch between 8 and 11. 8. Rules will run with pkg_ver3 11. Rules will run with pkg_ver2 until it gets updated by KnowlegeAgent+Guvnor Expected results: UrlResource.getInputStream() should not return a newer version than the local cache file. So: 8. Rules will run with pkg_ver2 11. Rules will run with pkg_ver2 until it gets updated by KnowlegeAgent+Guvnor
Created attachment 829091 [details] BRMS531Ex08_kagent_oldFileCache.zip Attaching a reproducer which includes repository_export_kagent_test.xml. Feel free to contact me if you have any difficulty in reproduction.
Sent a pull request to 5.6.x branch (Is it preferred than 5.3.x branch?) https://github.com/droolsjbpm/drools/pull/291
Applied to 5.6.x and master. (5.6.x): http://github.com/droolsjbpm/drools/commit/fe42528c9 (master): http://github.com/droolsjbpm/drools/commit/af0028cbd Thank you for providing the fix.
Hi Edson, This BZ is related to BRMS 5.3.1. If it is MODIFIED then the fix should be there in 5.3.x branch. Could u commit there too please? I am adding it to Roll Up Patch #4. Thanks
Cherry-picked into 5.3.x as requested: http://github.com/droolsjbpm/drools/commit/aa41bdfc4
The step 6 in "Steps to Reproduce:" was wrong. Please change from: === 6. After stopping at the breakpoint, update an asset and build a package in Guvnor again (= pkg_ver3) === to: === 6. After stopping at the breakpoint, 'step over' one line to read the package from Guvnor. Then update an asset and build a package in Guvnor again (= pkg_ver3) ===