Bug 1034588 - stale local cache file in UrlResource
Summary: stale local cache file in UrlResource
Keywords:
Status: VERIFIED
Alias: None
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRE (Expert, Fusion)
Version: BRMS 5.3.1
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: GA
: ---
Assignee: Nobody
QA Contact: Lukáš Petrovický
URL:
Whiteboard:
Depends On:
Blocks: 1022758 1044292
TreeView+ depends on / blocked
 
Reported: 2013-11-26 07:24 UTC by Toshiya Kobayashi
Modified: 2022-08-12 04:38 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1044292 (view as bug list)
Environment:
Last Closed:
Type: Bug


Attachments (Terms of Use)
BRMS531Ex08_kagent_oldFileCache.zip (2.93 MB, application/zip)
2013-11-26 07:27 UTC, Toshiya Kobayashi
no flags Details

Description Toshiya Kobayashi 2013-11-26 07:24:51 UTC
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

Comment 1 Toshiya Kobayashi 2013-11-26 07:27:21 UTC
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.

Comment 3 Toshiya Kobayashi 2013-11-26 11:55:14 UTC
Sent a pull request to 5.6.x branch (Is it preferred than 5.3.x branch?)

https://github.com/droolsjbpm/drools/pull/291

Comment 4 Edson Tirelli 2013-12-18 03:24:40 UTC
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.

Comment 5 Alessandro Lazarotti 2014-01-08 17:59:51 UTC
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

Comment 6 Edson Tirelli 2014-01-08 20:01:01 UTC
Cherry-picked into 5.3.x as requested:

http://github.com/droolsjbpm/drools/commit/aa41bdfc4

Comment 7 Toshiya Kobayashi 2014-02-06 06:55:39 UTC
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)
===


Note You need to log in before you can comment on or make changes to this bug.