From 6a773f53893037cfd4fb859d39dc1d756a5fd504 Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Tue, 1 Dec 2026 14:11:36 -0500 Subject: [PATCH] fix: Tolerate status updates with no error in the data source outage tracker OutageTracker.recordError dereferenced the error of every INTERRUPTED update, but DataSourceUpdateSink.updateStatus allows the error to be null. FDv2DataSource reports INTERRUPTED with no error while all synchronizers are backing off, which threw a NullPointerException, ended the data source loop, and stopped all further requests. Only record an error when one is present; the outage is still started and timed. Fixes #292 --- .../sdk/server/DataSourceUpdatesImpl.java | 10 ++-- .../sdk/server/DataSourceUpdatesImplTest.java | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceUpdatesImpl.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceUpdatesImpl.java index 2f945f64..55bb1061 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceUpdatesImpl.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceUpdatesImpl.java @@ -318,12 +318,16 @@ void trackDataSourceState(State newState, ErrorInfo newError) { // with a timeout for logging the outage at a higher level, schedule that timeout. if (inOutage) { // We were already in one - just record this latest error for logging later. - recordError(newError); - } else { + if (newError != null) { + recordError(newError); + } + } else { // We weren't already in one, so set the timeout and start recording errors. inOutage = true; errorCounts.clear(); - recordError(newError); + if (newError != null) { + recordError(newError); + } timeoutFuture = sharedExecutor.schedule(this::onTimeout, loggingTimeout.toMillis(), TimeUnit.MILLISECONDS); } } else { diff --git a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/DataSourceUpdatesImplTest.java b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/DataSourceUpdatesImplTest.java index fee4df7d..4b8f8130 100644 --- a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/DataSourceUpdatesImplTest.java +++ b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/DataSourceUpdatesImplTest.java @@ -622,6 +622,53 @@ public void outageTimeoutLogging() throws Exception { assertThat(errorsDesc, containsString("ERROR_RESPONSE(502) (1 time)")); } + @Test + public void outageTrackerToleratesInterruptedStatusWithNoError() throws Exception { + BlockingQueue outageErrors = new LinkedBlockingQueue<>(); + Duration outageTimeout = Duration.ofMillis(100); + + DataSourceUpdatesImpl updates = new DataSourceUpdatesImpl( + inMemoryDataStore(), + null, + flagChangeBroadcaster, + EventBroadcasterImpl.forDataSourceStatus(sharedExecutor, nullLogger), + sharedExecutor, + outageTimeout, + nullLogger + ); + updates.onOutageErrorLog = outageErrors::add; + + // a status update during an outage is not required to carry an error + updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromHttpError(401)); + updates.updateStatus(State.INTERRUPTED, null); + + String errorsDesc = awaitValue(outageErrors, 250, TimeUnit.MILLISECONDS); + assertThat(errorsDesc, containsString("ERROR_RESPONSE(401) (1 time)")); + } + + @Test + public void outageTrackerToleratesFirstInterruptedStatusWithNoError() throws Exception { + BlockingQueue outageErrors = new LinkedBlockingQueue<>(); + Duration outageTimeout = Duration.ofMillis(100); + + DataSourceUpdatesImpl updates = new DataSourceUpdatesImpl( + inMemoryDataStore(), + null, + flagChangeBroadcaster, + EventBroadcasterImpl.forDataSourceStatus(sharedExecutor, nullLogger), + sharedExecutor, + outageTimeout, + nullLogger + ); + updates.onOutageErrorLog = outageErrors::add; + + // the outage must still be timed even when its first report carries no error + updates.updateStatus(State.VALID, null); + updates.updateStatus(State.INTERRUPTED, null); + + awaitValue(outageErrors, 250, TimeUnit.MILLISECONDS); + } + @Test public void applyFullChangeSetSendsEventsForNewlyAddedFlags() throws Exception { DataSourceUpdatesImpl updates = makeInstance(inMemoryDataStore());