Trivy can hang if an error occurs scanning a container image with --slow option #4343
Closed
2 tasks done
Labels
kind/bug
Categorizes issue or PR as related to a bug.
Discussed in #4335
Originally posted by mpoindexter May 12, 2023
Description
When scanning with --slow, any error will deadlock the scan if the image has more than one layer.
This is because here https://github.com/aquasecurity/trivy/blob/main/pkg/fanal/artifact/image/image.go#L243 the goroutine blocks on sending to the
errCh
channel, while it is holding thelimit
semaphore which is only released in the defer. This means that the goroutine callingInspect
is then blocked at https://github.com/aquasecurity/trivy/blob/main/pkg/fanal/artifact/image/image.go#L223 and can never get to https://github.com/aquasecurity/trivy/blob/main/pkg/fanal/artifact/image/image.go#L259 to read fromerrCh
and unblock the scan goroutine.Desired Behavior
Trivy does not hang when an error occurs
Actual Behavior
Trivy hangs
Reproduction Steps
Can be reproduced by running `trivy image localstack/localstack:0.8.6 --java-db-repository invalid --slow` after clearing trivy caches Note that specifying an invalid java db repository is just an easy way to reproducibly get an error, any error can cause this
Target
Container Image
Scanner
Vulnerability
Output Format
JSON
Mode
Client/Server
Debug Output
Operating System
MacOS
Version
Checklist
trivy --reset
The text was updated successfully, but these errors were encountered: