configcat / java-sdk

ConfigCat SDK for Java. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/java
MIT License
20 stars 6 forks source link

When calling force refresh, failure to write on cache will make it impossible to refresh again without server state change #12

Closed ls-rein-martha closed 2 years ago

ls-rein-martha commented 2 years ago

Describe the bug

Issue on calling forceRefresh() when previous refresh fail on writing to cache. With custom ConfigCache. It is possible to fail when writing to cache, example: distributed cache can fail to write (even though the chance is very small it still exist).

To reproduce

Use MANUAL polling mode. Create a feature flag, lets create String for easy check, with initial value: "INITIAL" Create a custom ConfigCache, like below to mimic exception:

    public class FailWriteEveryThirdRequest extends ConfigCache{
        Map<String, String> map = new HashMap<>();
        AtomicInteger counter = new AtomicInteger(1);

        @Override
        protected String read(String key) throws Exception {
            return map.get(key);
        }

        @Override
        protected void write(String key, String value) throws Exception {
            if(counter.getAndIncrement() % 2 == 0){
                throw new RuntimeException("I fail for some reason"); // just to mimic exception on failure writing
            }
            map.put(key, value);
        }
    }

Update the value and refresh -> everything good -> before refresh for the second time (that will throw exception):

Do force refresh again:

Root cause:

Expected behavior

At minimum, when fail to write to cache, the next successful refresh (done manually) should be able to update the value. Better solution is server can know when there is a problem on writing and when client use webhook, server can do retry mechanism.

Screenshots

N/A

SDK version

Tried at 7.0.4 and 7.0.5

SDK configuration

Default configuration also can reproduce. (Just use manual polling and manual force refresh)

Logs

N/A

Language/Framework version

Java 8

Platform

Any

z4kn4fein commented 2 years ago

Hi @ls-rein-martha, thank you for reporting this issue! I'm going to start working on this and I'll let you know when the fix is ready.

z4kn4fein commented 2 years ago

Hi @ls-rein-martha, I released the fix for this issue in v7.0.6, could you please check that it works now on your end as expected? Thanks!

ls-rein-martha commented 2 years ago

Hi @ls-rein-martha, I released the fix for this issue in v7.0.6, could you please check that it works now on your end as expected? Thanks!

Hi @z4kn4fein thank you for quick fix. I will wait for the mvnrepo release to test, I have not see it available yet there. :)

ls-rein-martha commented 2 years ago

Tested. Fixed at v7.0.6.