CORDA-1588: Add an extra check in the attachment resolution flow to prevent duplicate attachment import if multiple transactions with the same attachment are being resolved at the same time.

This commit is contained in:
Andrius Dagys 2018-06-08 11:49:35 +01:00
parent 8ac7690987
commit 2558c9dcf7

View File

@ -147,7 +147,13 @@ class FetchAttachmentsFlow(requests: Set<SecureHash>,
override fun maybeWriteToDisk(downloaded: List<Attachment>) {
for (attachment in downloaded) {
serviceHub.attachments.importAttachment(attachment.open(), "$P2P_UPLOADER:${otherSideSession.counterparty.name}", null)
with(serviceHub.attachments) {
if (!hasAttachment(attachment.id)) {
importAttachment(attachment.open(), "$P2P_UPLOADER:${otherSideSession.counterparty.name}", null)
} else {
logger.info("Attachment ${attachment.id} already exists, skipping.")
}
}
}
}