Repository navigation
Description
Current Behavior
BOM upload is failing on 4.10 but not on 4.8.2. My webhook is informed of the problem:
BOM processing failure notification from "hello 5", BOM format is "CycloneDX", "1.4", cause is "Insert of object "org.dependencytrack.model.ProjectMetadata@8d67e8d" using statement "INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?)" failed : Unique index or primary key violation: "PUBLIC.PROJECT_METADATA_PROJECT_ID_IDX_INDEX_3 ON PUBLIC.PROJECT_METADATA(PROJECT_ID NULLS FIRST) VALUES ( /* 9 */ CAST(5 AS BIGINT) )"; SQL statement:\nINSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?) [23505-224]"
The D-T API logs show
2023-12-18 21:22:25,674 WARN [Persist] Insert of object "org.dependencytrack.model.ProjectMetadata@4688ac8e" using statement "INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?)" failed : Unique index or primary key violation: "PUBLIC.PROJECT_METADATA_PROJECT_ID_IDX_INDEX_3 ON PUBLIC.PROJECT_METADATA(PROJECT_ID NULLS FIRST) VALUES ( /* 33 */ CAST(33 AS BIGINT) )"; SQL statement:
INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?) [23505-224]
2023-12-18 21:22:25,689 ERROR [BomUploadProcessingTask] Error while processing bom
javax.jdo.JDODataStoreException: Insert of object "org.dependencytrack.model.ProjectMetadata@4688ac8e" using statement "INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?)" failed : Unique index or primary key violation: "PUBLIC.PROJECT_METADATA_PROJECT_ID_IDX_INDEX_3 ON PUBLIC.PROJECT_METADATA(PROJECT_ID NULLS FIRST) VALUES ( /* 33 */ CAST(33 AS BIGINT) )"; SQL statement:
INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?) [23505-224]
at org.datanucleus.api.jdo.JDOAdapter.getJDOExceptionForNucleusException(JDOAdapter.java:605)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:702)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:722)
at org.dependencytrack.tasks.BomUploadProcessingTask.lambda$inform$1(BomUploadProcessingTask.java:129)
at org.dependencytrack.persistence.QueryManager.lambda$runInTransaction$0(QueryManager.java:1346)
at org.dependencytrack.persistence.QueryManager.runInTransaction(QueryManager.java:1377)
at org.dependencytrack.persistence.QueryManager.runInTransaction(QueryManager.java:1345)
at org.dependencytrack.tasks.BomUploadProcessingTask.inform(BomUploadProcessingTask.java:127)
at alpine.event.framework.BaseEventService.lambda$publish$0(BaseEventService.java:110)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation: "PUBLIC.PROJECT_METADATA_PROJECT_ID_IDX_INDEX_3 ON PUBLIC.PROJECT_METADATA(PROJECT_ID NULLS FIRST) VALUES ( /* 33 */ CAST(33 AS BIGINT) )"; SQL statement:
INSERT INTO PROJECT_METADATA (AUTHORS,PROJECT_ID,SUPPLIER) VALUES (?,?,?) [23505-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:520)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.index.Index.getDuplicateKeyException(Index.java:527)
at org.h2.mvstore.db.MVSecondaryIndex.checkUnique(MVSecondaryIndex.java:223)
at org.h2.mvstore.db.MVSecondaryIndex.add(MVSecondaryIndex.java:184)
at org.h2.mvstore.db.MVTable.addRow(MVTable.java:519)
at org.h2.command.dml.Insert.insertRows(Insert.java:174)
at org.h2.command.dml.Insert.update(Insert.java:135)
at org.h2.command.CommandContainer.executeUpdateWithGeneratedKeys(CommandContainer.java:242)
at org.h2.command.CommandContainer.update(CommandContainer.java:163)
at org.h2.command.Command.executeUpdate(Command.java:256)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:216)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:174)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at org.datanucleus.store.rdbms.SQLController.executeStatementUpdate(SQLController.java:430)
at org.datanucleus.store.rdbms.request.InsertRequest.execute(InsertRequest.java:520)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObjectInTable(RDBMSPersistenceHandler.java:162)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObject(RDBMSPersistenceHandler.java:138)
at org.datanucleus.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:4587)
at org.datanucleus.state.StateManagerImpl.makePersistent(StateManagerImpl.java:4564)
at org.datanucleus.ExecutionContextImpl.persistObjectInternal(ExecutionContextImpl.java:2014)
at org.datanucleus.ExecutionContext.persistObjectInternal(ExecutionContext.java:320)
at org.datanucleus.ExecutionContextImpl.persistObjectWork(ExecutionContextImpl.java:1862)
at org.datanucleus.ExecutionContextImpl.persistObject(ExecutionContextImpl.java:1723)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:697)
... 10 common frames omitted
Steps to Reproduce
- I was not able to reproduce this using the D-T UI and uploading the same two SBOMs into a project. It only happened with the Go API.
Expected Behavior
In 4.8.2 it worked as I expected. I uploaded two files, then eventually the webhooks were called.
Dependency-Track Version
4.10.0
Dependency-Track Distribution
Container Image
Database Server
N/A
Database Server Version
No response
Browser
Google Chrome
Checklist
- I have read and understand the contributing guidelines
- I have checked the existing issues for whether this defect was already reported
Activity
nscuro commentedon Dec 19, 2023
@esnible Is this reproducible, or did it just happen once? Could it be related to concurrent BOM uploads to the same project perhaps?
esnible commentedon Dec 19, 2023
It is reproducible. It was reported to me on a different D-T instance, and I reproduce it on my instance every time. It went away when I went back to 4.8.2.
The upload request is
I am uploading two BOMs without waiting or checking the token. I am not uploading concurrently but as soon as the first BOMService.Upload() succeeds I start the second Upload().
If I have time this week I can narrow down the version that introduced this issue, and I'll try setting AutoCreate to false for the 2nd and subsequent SBOMs.
nscuro commentedon Dec 19, 2023
For the same project, or for different projects?
esnible commentedon Dec 19, 2023
Same project, same version.
esnible commentedon Feb 16, 2024
nscuro commentedon Feb 16, 2024
The underlying problem is that DT not currently serializes the processing of uploaded BOMs.
So both of the BOMs you're uploading may be processed concurrently.
I've been working on the BOM processing area of the code base, where I also left this note:
dependency-track/src/main/java/org/dependencytrack/tasks/BomUploadProcessingTaskV2.java
Lines 283 to 285 in a362ac5
The new logic already makes better use of DB transactions, which will help for updates of existing data, but not for insertion of new data. For that, we need explicit locking by project.
With all that being said, I'm curious what the use case is behind submitting the same BOM to the same project in such close succession?
esnible commentedon Feb 16, 2024
I am not uploading the same SBOM twice. I am uploading two different SBOMs that I wish to track together, because I will deploy them together as a single pod or single workload.
valentijnscholten commentedon Feb 18, 2024
The idea is that each project+version has exactly 1 SBOM. If you want to track multiple SBOMs in the same project+version, the most reliable thing to do is to merge them before uploading, for example using
cyclonedx merge ...