Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate key value violates unique constraint "scan_report_digest_registration_uuid_mime_type_key" #20644

Open
flbla opened this issue Jun 21, 2024 · 1 comment
Assignees

Comments

@flbla
Copy link
Contributor

flbla commented Jun 21, 2024

If you are reporting a problem, please make sure the following information are provided:

Expected behavior and actual behavior:

When a scan is launched (manually or via a push) we randomly get this error :

2024-06-13T14:23:13Z [ERROR] [/controller/event/handler/internal/artifact.go:259]: scan artifact ************************* failed, error: ERROR: duplicate key value violates unique constraint "scan_report_digest_registration_uuid_mime_type_key" (SQLSTATE 23505)

In my postgresql logs I can see :

2024-06-13 14:23:13 UTC-666aff97.4a66-LOG:  QUERY STATISTICS","detail": "! system usage stats:\n!\t0.000146 s user, 0.000000 s system, 0.005479 s elapsed\n!\t[0.315484 s user, 0.050385 s system total]\n!\t20940 kB max resident size\n!\t0/48 [672/864] filesystem blocks in/out\n!\t0/0 [0/1906] page faults/reclaims, 0 [0] swaps\n!\t0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent\n!\t2/0 [1487/2322] voluntary/involuntary context switches","statement": "commit
2024-06-13 14:23:13 UTC-666aff7a.49cc-ERROR:  duplicate key value violates unique constraint \"scan_report_digest_registration_uuid_mime_type_key\"","detail": "Key (digest, registration_uuid, mime_type)=(sha256:62b692583d8dada8d68dbc996c5e98fd397a5f3263f4149fde95cad749ba416b, ed4df02c-6216-11eb-980a-e2227a954221, application/vnd.security.vulnerability.report; version=1.1) already exists.","statement": "INSERT INTO \"scan_report\" (\"uuid\", \"digest\", \"registration_uuid\", \"mime_type\", \"report\", \"critical_cnt\", \"high_cnt\", \"medium_cnt\", \"low_cnt\", \"unknown_cnt\", \"none_cnt\", \"fixable_cnt\") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING \"id\"","schema_name": "public","table_name": "scan_report","constraint_name": "scan_report_digest_registration_uuid_mime_type_key

harbor core log :

2024-06-13T14:23:25Z [ERROR] [/controller/event/handler/internal/artifact.go:259]: scan artifact *************************  failed, error: a previous scan process is Running

it looks like harbor try to scan the same artifact more than once, but I don't know why.

Steps to reproduce the problem:
it's random

Versions:
Please specify the versions of following systems.

  • harbor version: 2.10.2
  • kubernetes : 1.28
@stonezdj
Copy link
Contributor

stonezdj commented Jul 8, 2024

Because there is an interval between the reportMgr.Get and the reportMgr.Create

oldReports, err := bc.manager.GetBy(bc.cloneCtx(ctx), art.Digest, r.UUID, mimeTypes)

reportUUID, err := bc.manager.Create(ctx, report)

If some other user trigger the scan of same digest at this interval, it will cause this issue.
To fix this issue, we need to change the reportMgr.Create into InsertOrUpdate

This issue is low impact because user could retrigger the scan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants