growthbook / growthbook-sdk-java

The Java SDK for GrowthBook (JVM, Android)
https://docs.growthbook.io/lib/java
MIT License
7 stars 10 forks source link

SDK Java doesn't reconnect when using SSE #52

Closed mvsmasiero closed 1 month ago

mvsmasiero commented 1 month ago

I have a scenario where I use the GrowthBook proxy and use the Java SDK's GBFeaturesRepository class using the SERVER_SENT_EVENTS strategy.

When the application loses connection with the proxy (the proxy may restart or there is a network issue) the GBFeaturesRepository doesn't reconnect to the proxy.

Bohdan-Kim commented 1 month ago

Hello @mvsmasiero! I suppose connection is stable for 5 minutes and after that connection is being closed. Is connection lasting, for example, 30min better for you?

Bohdan-Kim commented 1 month ago

It seems like the cause why it doesn't reconnect is Proxy off. When Backend is working GBFeaturesRepository successfully reconnects. image image

mvsmasiero commented 1 month ago

Hello @Bohdan-Kim

When the Java application loses connection to GB Proxy, this method on the GBFeatureRepository is called:

image

When the connectivity issue is fixed, the application only connects to GBProxy after restarting the application.

Bohdan-Kim commented 1 month ago

It seems like we should make changes to the sources in order to handle this.

Bohdan-Kim commented 1 month ago

The pull request was created according on the issue. We expect that calling initialize() method with retryOnFailure = true will lead to execution of this block: image

mvsmasiero commented 1 month ago

Hello @Bohdan-Kim , I've tested the solution.

With this solution, the Java application reconnects to GB Proxy successfully, but I've found a problem: if a flag is changed before the application reconnects, that change is not reflected.

I tested this change to fix it. What do you think?

image

Bohdan-Kim commented 1 month ago

if a flag is changed before the application reconnects How is it possible that the flag can be changed? Calling initialize() method the second time? The connection already established. Why calling the initialize() method again is needed?

mvsmasiero commented 1 month ago

I think the chances of this happening are low, but I believe it is important to evaluate this possibility. For example: The GB Proxy may be down and the Product Owner does not know about it and activates some Flag or makes some other change.

Bohdan-Kim commented 1 month ago

Ok