forked from Qortal/qortal
Synchronize the loop and break out of it before fetching arbitrary data files. Hopeful fix for ConcurrentModificationException, and maybe a potential deadlock.
This commit is contained in:
parent
618aaaf243
commit
694ea689c8
@ -84,6 +84,13 @@ public class ArbitraryDataFileManager extends Thread {
|
|||||||
private void processFileHashes(Long now) {
|
private void processFileHashes(Long now) {
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
|
|
||||||
|
ArbitraryTransactionData arbitraryTransactionData = null;
|
||||||
|
byte[] signature = null;
|
||||||
|
byte[] hash = null;
|
||||||
|
Peer peer = null;
|
||||||
|
boolean shouldProcess = false;
|
||||||
|
|
||||||
|
synchronized (arbitraryDataFileHashResponses) {
|
||||||
for (String hash58 : arbitraryDataFileHashResponses.keySet()) {
|
for (String hash58 : arbitraryDataFileHashResponses.keySet()) {
|
||||||
if (isStopping) {
|
if (isStopping) {
|
||||||
return;
|
return;
|
||||||
@ -91,7 +98,7 @@ public class ArbitraryDataFileManager extends Thread {
|
|||||||
|
|
||||||
Triple<Peer, String, Long> value = arbitraryDataFileHashResponses.get(hash58);
|
Triple<Peer, String, Long> value = arbitraryDataFileHashResponses.get(hash58);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
Peer peer = value.getA();
|
peer = value.getA();
|
||||||
String signature58 = value.getB();
|
String signature58 = value.getB();
|
||||||
Long timestamp = value.getC();
|
Long timestamp = value.getC();
|
||||||
|
|
||||||
@ -100,19 +107,34 @@ public class ArbitraryDataFileManager extends Thread {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] hash = Base58.decode(hash58);
|
hash = Base58.decode(hash58);
|
||||||
byte[] signature = Base58.decode(signature58);
|
signature = Base58.decode(signature58);
|
||||||
|
|
||||||
// Fetch the transaction data
|
// Fetch the transaction data
|
||||||
ArbitraryTransactionData arbitraryTransactionData = ArbitraryTransactionUtils.fetchTransactionData(repository, signature);
|
arbitraryTransactionData = ArbitraryTransactionUtils.fetchTransactionData(repository, signature);
|
||||||
if (arbitraryTransactionData == null) {
|
if (arbitraryTransactionData == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We want to process this file
|
||||||
|
shouldProcess = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldProcess) {
|
||||||
|
// Nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signature == null || hash == null || peer == null || arbitraryTransactionData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String hash58 = Base58.encode(hash);
|
||||||
LOGGER.debug("Fetching file {} from peer {} via response queue...", hash58, peer);
|
LOGGER.debug("Fetching file {} from peer {} via response queue...", hash58, peer);
|
||||||
this.fetchArbitraryDataFiles(repository, peer, signature, arbitraryTransactionData, Arrays.asList(hash));
|
this.fetchArbitraryDataFiles(repository, peer, signature, arbitraryTransactionData, Arrays.asList(hash));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
LOGGER.info("Unable to process file hashes: {}", e.getMessage());
|
LOGGER.info("Unable to process file hashes: {}", e.getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user