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 da7c1ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -907,16 +907,16 @@ 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() {
if (bestBlock.getNumber() == shutdownHook) {
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);

try {
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 Down Expand Up @@ -2097,7 +2095,7 @@ public synchronized void setBestBlock(Block block) {
public synchronized void close() {
// The main repository instance is stashed when the snapshot is created. If the current repository is a snapshot that means the main one is in the stack.
// We pop the stack until we get to the main repository instance that contains access too all the databases that must be closed.
while (repository.isSnapshot()) {
while (repository.isSnapshot() && !stateStack.isEmpty()) {
popState();
}

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 da7c1ae

Please sign in to comment.