From 2558c9dcf7f4fbfe32b1afc9363c229d9e30e0a3 Mon Sep 17 00:00:00 2001 From: Andrius Dagys Date: Fri, 8 Jun 2018 11:49:35 +0100 Subject: [PATCH] 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. --- .../main/kotlin/net/corda/core/internal/FetchDataFlow.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/net/corda/core/internal/FetchDataFlow.kt b/core/src/main/kotlin/net/corda/core/internal/FetchDataFlow.kt index 4a89cf2bc1..1feb959261 100644 --- a/core/src/main/kotlin/net/corda/core/internal/FetchDataFlow.kt +++ b/core/src/main/kotlin/net/corda/core/internal/FetchDataFlow.kt @@ -147,7 +147,13 @@ class FetchAttachmentsFlow(requests: Set, override fun maybeWriteToDisk(downloaded: List) { 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.") + } + } } }