Skip to content

Commit

Permalink
add duplicate report check for race condition. Closes #492
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Mar 16, 2024
1 parent 7e74fe6 commit 4f7aed9
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile
import java.sql.SQLIntegrityConstraintViolationException

private val logger = KotlinLogging.logger {}

Expand Down Expand Up @@ -110,7 +111,15 @@ class ReportService(
versionCode = versionCode,
versionFlavor = flavor ?: "",
)
reportRepository.create(report, attachments.associate { (it.originalFilename ?: it.name) to it.bytes })
try {
reportRepository.create(report, attachments.associate { (it.originalFilename ?: it.name) to it.bytes })
} catch (e: SQLIntegrityConstraintViolationException) {
reportRepository.find(reportId)?.let {
logger.warn { "Race condition while saving $reportId, ignoring." }
return it
}
throw e
}
mailService?.onNewReport(report)
return report
}
Expand Down

0 comments on commit 4f7aed9

Please sign in to comment.