Skip to content

Commit cc40b34

Browse files
committed
problem: clients locks forever if auth failed
solution: put auth errors to stderr and clear auth queue on errors (so it can reauth later)
1 parent e05be46 commit cc40b34

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

emerald-api/src/main/java/io/emeraldpay/impl/AuthHolder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ public void setAuth(MetadataHandler auth) {
8686
this.auth = auth;
8787
if (auth.isReady()) {
8888
for (Consumer<MetadataHandler> listener : authQueue) {
89-
listener.accept(auth);
89+
try {
90+
listener.accept(auth);
91+
} catch (Exception e) {
92+
System.err.println("Error in auth listener: " + e.getMessage());
93+
// ignore any exceptions in the listener, it should not block the auth update
94+
}
9095
}
9196
authQueue.clear();
9297
}

emerald-api/src/main/java/io/emeraldpay/impl/TokenCredentials.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ public boolean isReady() {
137137
@Override
138138
public void request(AuthHolder caller) {
139139
executor.submit(() -> {
140-
if (jwt == null) {
141-
authSync();
142-
} else {
143-
refreshSync();
140+
try {
141+
if (jwt == null) {
142+
authSync();
143+
} else {
144+
refreshSync();
145+
}
146+
} catch (Exception e) {
147+
System.err.println("Error during the authentication: " + e.getMessage());
148+
return;
144149
}
145150
caller.setAuth(this);
146151
});

0 commit comments

Comments
 (0)