mirror of
https://github.com/corda/corda.git
synced 2025-02-21 01:42:24 +00:00
CORDA-1865 Fix race on inserting attachments (#3734)
* CORDA-1865 Fix race on inserting attachments * CORDA-1865 Fix race on inserting attachments
This commit is contained in:
parent
2e03c7f8c0
commit
6499a13951
@ -18,6 +18,7 @@ import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
import net.corda.core.utilities.UntrustworthyData
|
||||
import net.corda.core.utilities.unwrap
|
||||
import java.nio.file.FileAlreadyExistsException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -149,9 +150,15 @@ class FetchAttachmentsFlow(requests: Set<SecureHash>,
|
||||
for (attachment in downloaded) {
|
||||
with(serviceHub.attachments) {
|
||||
if (!hasAttachment(attachment.id)) {
|
||||
importAttachment(attachment.open(), "$P2P_UPLOADER:${otherSideSession.counterparty.name}", null)
|
||||
try {
|
||||
importAttachment(attachment.open(), "$P2P_UPLOADER:${otherSideSession.counterparty.name}", null)
|
||||
} catch (e: FileAlreadyExistsException) {
|
||||
// This can happen when another transaction will insert the same attachment during this transaction.
|
||||
// The outcome is the same (the attachment is imported), so we can ignore this exception.
|
||||
logger.debug("Attachment ${attachment.id} already inserted.")
|
||||
}
|
||||
} else {
|
||||
logger.info("Attachment ${attachment.id} already exists, skipping.")
|
||||
logger.debug("Attachment ${attachment.id} already exists, skipping.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user