Skip to content

Commit

Permalink
fix(remote): enforce timeout with slave containers even if interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Feb 4, 2024
1 parent 0db20ae commit 75a7483
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/org/arl/fjage/remote/ConnectionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,25 @@ JsonMessage printlnAndGetResponse(String s, String id, long timeout) {
if (conn == null) return null;
if (keepAlive && !alive && container instanceof MasterContainer) return null;
pending.put(id, id);
try {
synchronized(id) {
println(s);
id.wait(timeout);
long deadline = System.currentTimeMillis() + timeout;
synchronized(id) {
println(s);
long dt = deadline - System.currentTimeMillis();
while (dt > 0) {
try {
id.wait(dt);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
Object rv = pending.get(id);
if (rv instanceof JsonMessage) {
pending.remove(id);
return (JsonMessage)rv;
}
dt = deadline - System.currentTimeMillis();
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
Object rv = pending.get(id);
pending.remove(id);
if (rv instanceof JsonMessage) return (JsonMessage)rv;
if (keepAlive && alive) {
alive = false;
log.fine("Connection dead");
Expand Down

0 comments on commit 75a7483

Please sign in to comment.