Skip to content

BOM Upload failure on 4.10 but not 4.8.2 #3324

Open

Description

@esnible

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

  1. 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

Activity

  1. added
    defect
    on Dec 18, 2023
  2. nscuro commented on Dec 19, 2023

    @nscuro
    Member

    @esnible Is this reproducible, or did it just happen once? Could it be related to concurrent BOM uploads to the same project perhaps?

  3. esnible commented on Dec 19, 2023

    @esnible
    Author

    @esnible Is this reproducible, or did it just happen once? Could it be related to concurrent BOM uploads to the same project perhaps?

    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

    dtrack.BOMUploadRequest{
    		ProjectName:    name,
    		ProjectVersion: DefaultDTProjectVersion,
    		AutoCreate:     true,
    		BOM:            base64.StdEncoding.EncodeToString(bySBOM),
    	}
    

    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.

  4. nscuro commented on Dec 19, 2023

    @nscuro
    Member

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

    For the same project, or for different projects?

  5. esnible commented on Dec 19, 2023

    @esnible
    Author

    For the same project, or for different projects?

    Same project, same version.

  6. esnible commented on Feb 16, 2024

    @esnible
    Author
    • I have verified this problem still occurs with 4.10.1
    • I have verified this problem occurs with using the JSON API and using multipart/form-data to upload BOMs
    • Introducing a 15 second sleep between uploads made the problem go away.
  7. nscuro commented on Feb 16, 2024

    @nscuro
    Member

    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:

    // TODO: Introduce locking by project ID / UUID to avoid processing BOMs for the same project concurrently.

    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?

  8. esnible commented on Feb 16, 2024

    @esnible
    Author

    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?

    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.

  9. valentijnscholten commented on Feb 18, 2024

    @valentijnscholten
    Contributor

    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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    defect

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions