Skip to content

Commit

Permalink
Send UI to Unknown Error if auth token cannot be refreshed after a fe…
Browse files Browse the repository at this point in the history
…w tries (#1193)
  • Loading branch information
nbauernfeind authored Sep 1, 2021
1 parent 4a97d0a commit f1ccb63
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ private enum State {
private Map<String, JsVariableDefinition> knownFields = new HashMap<>();
private ResponseStreamWrapper<FieldsChangeUpdate> fieldsChangeUpdateStream;

private long lastSuccessResponseTime = 0;
private static final long GIVE_UP_TIMEOUT_MS = 10_000;

public WorkerConnection(QueryConnectable<?> info, Supplier<Promise<ConnectToken>> authTokenPromiseSupplier) {
this.info = info;
this.config = new ClientConfiguration();
Expand Down Expand Up @@ -305,8 +308,10 @@ private void connectToWorker(Supplier<Promise<ConnectToken>> authTokenPromiseSup

public void checkStatus(ResponseStreamWrapper.Status status) {
// TODO provide simpler hooks to retry auth, restart the stream
final long now = System.currentTimeMillis();
if (status.isOk()) {
// success, ignore
lastSuccessResponseTime = now;
} else if (status.getCode() == Code.Unauthenticated) {
// TODO re-create session once?
// for now treating this as fatal, UI should encourage refresh to try again
Expand All @@ -316,6 +321,13 @@ public void checkStatus(ResponseStreamWrapper.Status status) {
info.notifyConnectionError(status);
} else if (status.getCode() == Code.Unavailable) {
// TODO skip re-authing for now, just backoff and try again
if (lastSuccessResponseTime == 0) {
lastSuccessResponseTime = now;
} else if (now - lastSuccessResponseTime >= GIVE_UP_TIMEOUT_MS) {
// this actually seems to be a problem; likely the worker has unexpectedly exited
// UI should encourage refresh to try again (which will probably fail; but at least doesn't look "OK")
info.notifyConnectionError(status);
}
} // others probably are meaningful to the caller
}

Expand Down Expand Up @@ -354,14 +366,15 @@ private void authUpdate(HandshakeResponse handshakeResponse) {
sessionServiceClient.refreshSessionToken(req, metadata, (fail, success) -> {
if (fail != null) {
// TODO set a flag so others know not to try until we re-trigger initial auth
// TODO re-trigger auth
// TODO re-trigger auth; but for now let's try again using our last successful auth
checkStatus((ResponseStreamWrapper.Status) fail);
authUpdate(handshakeResponse);
return;
}
// mark the new token, schedule a new check
authUpdate(success);
});
}, 5000);
}, 2500);
}

private void notifyLog(LogItem log) {
Expand Down

0 comments on commit f1ccb63

Please sign in to comment.