-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Is there an existing issue for this?
- I have searched the existing issues
SDK Version
3.2.0-alpha to 4.2.2.
Since this commit: Update HttpProjectConfigManager to use Last-Modified time (https://github.com/optimizely/java-sdk/pull/292)
Current Behavior
If the initialization of the configuration file fails, the configuration file remains un-initilialized indefinitely until the server/pod is restarted, or the configuration gets updated on Optimizely platform.
Expected Behavior
If the configuration file cannot be initialized at server start-up (eg: because Optimizely is down or takes to much time to respond), then during the next configuration poll, the configuration should be updated, even if Optimizely returns an HTTP 304 (Not Modified) code.
Steps To Reproduce
- At initialization of the
PollingProjectConfigManager
the connection is broken, or there is a time out, or an error. =>PollingProjectConfigManager.currentProjectConfig
is empty. - 5min later,
PollingProjectConfigManager.poll()
polls the config file, but receives HTTP 304 from Optimizely =>PollingProjectConfigManager.currentProjectConfig
remains empty. - 5min later, still no modification on the configuration =>
PollingProjectConfigManager.currentProjectConfig
remains empty. PollingProjectConfigManager.currentProjectConfig
is never initialized (except if a modification on the configuration is done on Optimizely side, or the server is restarted).
Java Version
No response
Link
No response
Logs
No response
Severity
Affecting users
Workaround/Solution
See the HttpProjectConfigManager
:
java-sdk/core-httpclient-impl/src/main/java/com/optimizely/ab/config/HttpProjectConfigManager.java
Lines 95 to 121 in 746e815
public String getDatafileFromResponse(HttpResponse response) throws NullPointerException, IOException { | |
StatusLine statusLine = response.getStatusLine(); | |
if (statusLine == null) { | |
throw new ClientProtocolException("unexpected response from event endpoint, status is null"); | |
} | |
int status = statusLine.getStatusCode(); | |
// Datafile has not updated | |
if (status == HttpStatus.SC_NOT_MODIFIED) { | |
logger.debug("Not updating ProjectConfig as datafile has not updated since " + datafileLastModified); | |
return null; | |
} | |
if (status >= 200 && status < 300) { | |
// read the response, so we can close the connection | |
HttpEntity entity = response.getEntity(); | |
Header lastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED); | |
if (lastModifiedHeader != null) { | |
datafileLastModified = lastModifiedHeader.getValue(); | |
} | |
return EntityUtils.toString(entity, "UTF-8"); | |
} else { | |
throw new ClientProtocolException("unexpected response when trying to fetch datafile, status: " + status); | |
} | |
} |
Here, the condition handling the HttpStatus.SC_NOT_MODIFIED
should check if the currentProjectConfig
is initialized or not. If it is empty, it means the configuration file has never been initialized properly and the configuration should thus be returned.
Recent Change
No response
Conflicts
No response