Skip to content

Commit

Permalink
close abort_call thread leak when no api available
Browse files Browse the repository at this point in the history
  • Loading branch information
vuapo-eth committed Jun 15, 2018
1 parent 4c11ae5 commit afcbee0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main/java/isf/logic/TimeAbortCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public abstract class TimeAbortCall {
private static final UIManager UIM = new UIManager("TimeAbrt");
public static final ThreadGroup TIME_ABORT_CALL_THREAD = new ThreadGroup("TimeAbortCallThread");
public static final ThreadGroup TIME_ABORT_CALL_THREAD = new ThreadGroup("TimeAbortCallThread");

private final String actionName;
private final int tolerance;
Expand All @@ -32,7 +32,7 @@ public void run() {
success.o = true;
synchronized (res) { res.notify(); }
}
};
};

while(true) {
try {
Expand All @@ -50,6 +50,7 @@ public void run() {
try {
synchronized (res) { res.wait(timeLimitSeconds*1000); }
} catch (InterruptedException e) {
t.interrupt();
UIM.logException(e, true);
}
if(!(boolean)success.o) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/isf/spam/NodeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean onCall() {

if(!t.call(CONNECTING_DURATION_TOLERACE)) return false;

String isNodeSynced = isNodeSynced(api);
String isNodeSynced = isNodeSynced(api, true);
if(isNodeSynced != null)
uim.logDbg(String.format(R.STR.getString("nodes_action_changing"), buildNodeAddress(api), api, isNodeSynced));
return isNodeSynced == null;
Expand Down Expand Up @@ -227,7 +227,7 @@ public static boolean[] getLatestInclusion(String[] hashes) {
return getInclusionStateResponse.getStates();
}

public static GetNodeInfoResponse getNodeInfo(final int parApi, boolean tryMultipleTimes) {
public static GetNodeInfoResponse getNodeInfo(final int parApi, final boolean tryingToCreateConnection, int amountOfTries) {

final ObjectWrapper api = new ObjectWrapper(parApi);
final ObjectWrapper res = new ObjectWrapper(null);
Expand All @@ -241,13 +241,13 @@ public boolean onCall() {
res.o = apis[(int)api.o].getNodeInfo();
return true;
} catch (Throwable e) {
api.o = handleThrowableFromIotaAPI(action, e, (int)api.o);
if(!tryingToCreateConnection) api.o = handleThrowableFromIotaAPI(action, e, (int)api.o);
return false;
}
}
};

do { tb.call(NODEINFO_DURATION_TOLERANCE); } while(tryMultipleTimes);
do { tb.call(NODEINFO_DURATION_TOLERANCE); } while(res.o == null && amountOfTries-- > 0);
return (GetNodeInfoResponse) res.o;
}

Expand Down Expand Up @@ -308,11 +308,11 @@ private static int handleThrowableFromIotaAPI(String failedAction, Throwable e,
return getRotatedAPI();
}

private static String isNodeSynced(int api) {
private static String isNodeSynced(int api, boolean tryingToCreateConnection) {

GetNodeInfoResponse getNodeInfoResponse = null;
try {
getNodeInfoResponse = getNodeInfo(api, false);
getNodeInfoResponse = getNodeInfo(api, tryingToCreateConnection, 3);
} catch (Throwable e) {
return e.getClass().getName() + ": " + e.getMessage();
}
Expand Down Expand Up @@ -399,7 +399,7 @@ private static void doSyncCheck(final int api) {
new Thread(DO_SYNC_CHECK_THREAD_GROUP,"doSyncCheck("+api+")") {
@Override
public void run() {
String error = isNodeSynced(api);
String error = isNodeSynced(api, false);
if(error != null) connectToAnyNode(api, error);
}
}.start();
Expand Down

0 comments on commit afcbee0

Please sign in to comment.