forked from Qortal/qortal
Attempt to acquire a blockchain lock (for up to 5 seconds) before shutting down the repository.
This should fix conflicts caused by the synchronizer and controller now being on separate threads. It may also reduce the chances of the database corrupting on shutdown, but this remains to be seen.
This commit is contained in:
parent
640bcdd504
commit
7338f5f985
@ -870,6 +870,17 @@ public class Controller extends Thread {
|
|||||||
// We were interrupted while waiting for thread to join
|
// We were interrupted while waiting for thread to join
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we're the only thread modifying the blockchain when shutting down the repository
|
||||||
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
|
try {
|
||||||
|
if (!blockchainLock.tryLock(5, TimeUnit.SECONDS)) {
|
||||||
|
LOGGER.debug("Couldn't acquire blockchain lock even after waiting 5 seconds");
|
||||||
|
// Proceed anyway, as we have to shut down
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.info("Interrupted when waiting for blockchain lock");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOGGER.info("Shutting down repository");
|
LOGGER.info("Shutting down repository");
|
||||||
RepositoryManager.closeRepositoryFactory();
|
RepositoryManager.closeRepositoryFactory();
|
||||||
@ -877,6 +888,11 @@ public class Controller extends Thread {
|
|||||||
LOGGER.error("Error occurred while shutting down repository", e);
|
LOGGER.error("Error occurred while shutting down repository", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release the lock if we acquired it
|
||||||
|
if (blockchainLock.isHeldByCurrentThread()) {
|
||||||
|
blockchainLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER.info("Shutting down NTP");
|
LOGGER.info("Shutting down NTP");
|
||||||
NTP.shutdownNow();
|
NTP.shutdownNow();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user