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. (#3599)

This commit is contained in:
Katelyn Baker 2018-07-13 18:14:34 +01:00 committed by GitHub
parent c73647b4fe
commit 143379dad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.")
}
}
}
}