Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ public void onError(Throwable t) {
if (code >= 400 && code < 500) {
logger.error("Encountered non-retriable error: {}. Aborting connection to stream. Verify correct Mobile Key and Stream URI", code);
running = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the original callback order, but we should set connection401Error before the callbacks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated — connection401Error is now set before the callback, while dataSourceUpdateSink.shutDown() remains after the callback to preserve the original status listener notification ordering.

The startWithHttp401ShutsDownSink test retains the polling workaround for shutDownCalled since shutDown() still executes after the callback returns. The startWithHttp401PreventsSubsequentStart test no longer needs any workaround since connection401Error is set before the callback unblocks.

resultCallback.onError(new LDInvalidResponseCodeFailure("Unexpected Response Code From Stream Connection", t, code, false));
if (code == 401) {
connection401Error = true;
}
resultCallback.onError(new LDInvalidResponseCodeFailure("Unexpected Response Code From Stream Connection", t, code, false));
if (code == 401) {
dataSourceUpdateSink.shutDown();
}
stop(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,8 @@ public void startWithHttp401ShutsDownSink() throws Exception {
LDInvalidResponseCodeFailure failure = (LDInvalidResponseCodeFailure) error;
assertEquals(401, failure.getResponseCode());
assertFalse(failure.isRetryable());
// The background thread calls resultCallback.onError() before
// dataSourceUpdateSink.shutDown(), so shutDownCalled may not be true yet.
// Poll briefly to allow the background thread to complete.
// shutDown() is called after the error callback, so we need to
// wait briefly for the background thread to complete the call.
long deadline = System.currentTimeMillis() + 1000;
while (!dataSourceUpdateSink.shutDownCalled && System.currentTimeMillis() < deadline) {
Thread.sleep(10);
Expand Down