Skip to content

Commit

Permalink
Fixed the kernel shutdown hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Mar 17, 2020
1 parent 5fb5e03 commit 08e4c58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -907,15 +907,15 @@ public Pair<ByteArrayWrapper, Long> findMissingAncestor(Block block) {
public static boolean reachedFullSync = false;

public ImportResult tryToConnect(final Block block) {
checkKernelShutdownForCLI();
return tryToConnect(new BlockWrapper(block));
}

public synchronized ImportResult tryToConnect(final BlockWrapper blockWrapper) {
checkKernelShutdownForCLI();
return tryToConnectWithTimedExecution(blockWrapper).getLeft();
}

private void checkKernelShutdownForCLI() {
public void checkKernelShutdownForCLI() {
if (bestBlock.getNumber() == shutdownHook) {
LOG.info("Shutting down and dumping heap as indicated by CLI request since block number {} was reached.", shutdownHook);

Expand Down Expand Up @@ -949,8 +949,6 @@ public synchronized Triple<Long, Set<ByteArrayWrapper>, ImportResult> tryToConne
ImportResult importResult = null;
Set<ByteArrayWrapper> imported = new HashSet<>();
for (Block block : blockRange) {
checkKernelShutdownForCLI();

Pair<ImportResult, Long> result = tryToConnectWithTimedExecution(new BlockWrapper(block));
importResult = result.getLeft();
long importTime = result.getRight();
Expand All @@ -974,6 +972,10 @@ public synchronized Triple<Long, Set<ByteArrayWrapper>, ImportResult> tryToConne
} else {
imported.add(block.getHashWrapper());
}

if (bestBlock.getNumber() == shutdownHook || (enableFullSyncCheck && reachedFullSync)) {
break;
}
}
return Triple.of(bestBlock.getNumber(), imported, importResult);
}
Expand Down
2 changes: 2 additions & 0 deletions modAionImpl/src/org/aion/zero/impl/sync/TaskImportBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ private SyncMode processBatch(SyncMode syncMode, List<Block> batch, String displ
syncStats.updatePeerBlocks(displayId, count, BlockType.IMPORTED);
log.info("<import-status: node = {}, from = #{}, to = #{}, time elapsed = {} ms>", displayId, first, currentBest, importDuration);
}

chain.checkKernelShutdownForCLI();
} catch (Exception e) {
log.error("<import-block throw> ", e);

Expand Down

0 comments on commit 08e4c58

Please sign in to comment.