Skip to content

fix(providers): clean up temp storage on errors#537

Merged
willmurphyscode merged 1 commit intomainfrom
fix-cleanup-on-err
Mar 6, 2026
Merged

fix(providers): clean up temp storage on errors#537
willmurphyscode merged 1 commit intomainfrom
fix-cleanup-on-err

Conversation

@willmurphyscode
Copy link
Copy Markdown
Contributor

Previously, providers could allocate a new image struct, then read from it, and then on err would discard it, leading to a temp file leak. Instead, if the Read call on the image fails, pre-emptively call clean up before discarding the allocated image struct.

Previously, providers could allocate a new image struct, then read from
it, and then on err would discard it, leading to a temp file leak.
Instead, if the Read call on the image fails, pre-emptively call clean
up before discarding the allocated image struct.

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

Benchmark Test Results

Benchmark results from the latest changes vs base branch
make .tool/task
make[1]: Entering directory '/home/runner/work/stereoscope/stereoscope'
make[1]: Leaving directory '/home/runner/work/stereoscope/stereoscope'
.tool/task show-benchstat
?   	github.com/anchore/stereoscope	[no test files]
?   	github.com/anchore/stereoscope/examples	[no test files]
PASS
ok  	github.com/anchore/stereoscope/internal	0.004s
?   	github.com/anchore/stereoscope/internal/bus	[no test files]
PASS
ok  	github.com/anchore/stereoscope/internal/containerd	0.007s
PASS
ok  	github.com/anchore/stereoscope/internal/docker	0.004s
?   	github.com/anchore/stereoscope/internal/log	[no test files]
PASS
ok  	github.com/anchore/stereoscope/internal/podman	0.005s
?   	github.com/anchore/stereoscope/pkg/event	[no test files]
?   	github.com/anchore/stereoscope/pkg/event/parsers	[no test files]
goos: linux
goarch: amd64
pkg: github.com/anchore/stereoscope/pkg/file
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkTarIndex-4   	   27202	     44244 ns/op	    5699 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27169	     46179 ns/op	    5703 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27154	     44259 ns/op	    5701 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27063	     44241 ns/op	    5701 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27016	     44208 ns/op	    5701 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27066	     44181 ns/op	    5700 B/op	      93 allocs/op
BenchmarkTarIndex-4   	   27000	     44657 ns/op	    5700 B/op	      93 allocs/op
PASS
ok  	github.com/anchore/stereoscope/pkg/file	11.604s
PASS
ok  	github.com/anchore/stereoscope/pkg/filetree	0.005s
?   	github.com/anchore/stereoscope/pkg/filetree/filenode	[no test files]
PASS
ok  	github.com/anchore/stereoscope/pkg/image	0.005s
PASS
ok  	github.com/anchore/stereoscope/pkg/image/containerd	0.007s
PASS
ok  	github.com/anchore/stereoscope/pkg/image/docker	0.005s
PASS
ok  	github.com/anchore/stereoscope/pkg/image/oci	0.005s
PASS
ok  	github.com/anchore/stereoscope/pkg/image/oci/credhelpers	0.005s
?   	github.com/anchore/stereoscope/pkg/image/podman	[no test files]
PASS
ok  	github.com/anchore/stereoscope/pkg/image/sif	0.004s
?   	github.com/anchore/stereoscope/pkg/imagetest	[no test files]
PASS
ok  	github.com/anchore/stereoscope/pkg/tree	0.003s
PASS
ok  	github.com/anchore/stereoscope/pkg/tree/node	0.003s
goos: linux
goarch: amd64
pkg: github.com/anchore/stereoscope/test/integration
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkSimpleImage_GetImage/docker-archive-4 	     997	   1199239 ns/op	  276940 B/op	    2296 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     982	   1217381 ns/op	  276912 B/op	    2296 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     982	   1209485 ns/op	  276981 B/op	    2296 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     976	   1213041 ns/op	  276877 B/op	    2296 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     988	   1200470 ns/op	  276570 B/op	    2295 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     986	   1289443 ns/op	  276691 B/op	    2295 allocs/op
BenchmarkSimpleImage_GetImage/docker-archive-4 	     956	   1294768 ns/op	  276597 B/op	    2295 allocs/op
--- FAIL: BenchmarkSimpleImage_GetImage/podman
    fixture_image_simple_test.go:175: could not get fixture image: unable to detect input for 'stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7', errs: podman not available: no host address
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 345B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load build context
#3 transferring context: 209B done
#3 DONE 0.0s

#4 [1/3] ADD file-1.txt /somefile-1.txt
#4 CACHED

#5 [2/3] ADD file-2.txt /somefile-2.txt
#5 CACHED

#6 [3/3] ADD target /
#6 CACHED

#7 exporting to image
#7 exporting layers done
#7 writing image sha256:b756b0ec11b464b55ef0951ace77a3d33a4731db08171929feda18e4f5d9deb0 done
#7 naming to docker.io/library/stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7 done
#7 naming to docker.io/library/stereoscope-fixture-image-simple:latest done
#7 DONE 0.0s
time="2026-03-06T10:43:38Z" level=warning msg="Failed to check deprecations" error="connection error: desc = \"transport: Error while dialing: dial unix /run/containerd/containerd.sock: connect: permission denied\""
ctr: connection error: desc = "transport: Error while dialing: dial unix /run/containerd/containerd.sock: connect: permission denied"
--- FAIL: BenchmarkSimpleImage_GetImage
    image_fixtures.go:193: using existing image tar: 'test-fixtures/cache/stereoscope-fixture-image-simple-04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7.tar' (size: 22528, modified: 2026-03-06 10:42:49.058237499 +0000 UTC, mode: -rw-r--r--)
    image_fixtures.go:241: Build docker image: name="stereoscope-fixture-image-simple" tag="04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
    image_fixtures.go:291: saveImage running: docker image save stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7
    image_fixtures.go:286: 
        	Error Trace:	/home/runner/work/stereoscope/stereoscope/pkg/imagetest/image_fixtures.go:286
        	            				/home/runner/work/stereoscope/stereoscope/pkg/imagetest/image_fixtures.go:162
        	            				/home/runner/work/stereoscope/stereoscope/pkg/imagetest/image_fixtures.go:152
        	            				/home/runner/work/stereoscope/stereoscope/pkg/imagetest/image_fixtures.go:33
        	            				/home/runner/work/stereoscope/stereoscope/test/integration/fixture_image_simple_test.go:163
        	            				/opt/hostedtoolcache/go/1.25.7/x64/src/testing/benchmark.go:245
        	            				/opt/hostedtoolcache/go/1.25.7/x64/src/runtime/asm_amd64.s:1693
        	Error:      	Received unexpected error:
        	            	exit status 1
        	Test:       	BenchmarkSimpleImage_GetImage
        	Messages:   	could not import docker image to containerd (shell out)
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   45607	     26140 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   45482	     26157 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   46077	     26065 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   45897	     26117 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   45826	     26040 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   46164	     26249 ns/op	    2616 B/op	      18 allocs/op
BenchmarkSimpleImage_FetchSquashedContents/docker-archive-4         	   45626	     26235 ns/op	    2616 B/op	      18 allocs/op
--- FAIL: BenchmarkSimpleImage_FetchSquashedContents
    image_fixtures.go:193: using existing image tar: 'test-fixtures/cache/stereoscope-fixture-image-simple-04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7.tar' (size: 22528, modified: 2026-03-06 10:42:49.058237499 +0000 UTC, mode: -rw-r--r--)
    image_fixtures.go:75: error getting fixture image: 'podman' 'image-simple' with request 'podman:stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7': unable to detect input for 'stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7', errs: podman not available: no host address
FAIL
exit status 1
FAIL	github.com/anchore/stereoscope/test/integration	20.379s
?   	github.com/anchore/stereoscope/test/integration/test-fixtures/registry	[no test files]
FAIL
goos: linux
goarch: amd64
pkg: github.com/anchore/stereoscope/pkg/file
cpu: AMD EPYC 7763 64-Core Processor                
ctr: 
           │ .tmp/benchmark-ca96a68.txt │
           │           sec/op           │
TarIndex-4                  44.24µ ± 4%

           │ .tmp/benchmark-ca96a68.txt │
           │            B/op            │
TarIndex-4                 5.567Ki ± 0%

           │ .tmp/benchmark-ca96a68.txt │
           │         allocs/op          │
TarIndex-4                   93.00 ± 0%

pkg: github.com/anchore/stereoscope/test/integration
                                      │ .tmp/benchmark-ca96a68.txt │
                                      │           sec/op           │
SimpleImage_GetImage/docker-archive-4                  1.213m ± 7%

                                      │ .tmp/benchmark-ca96a68.txt │
                                      │            B/op            │
SimpleImage_GetImage/docker-archive-4                 270.4Ki ± 0%

                                      │ .tmp/benchmark-ca96a68.txt │
                                      │         allocs/op          │
SimpleImage_GetImage/docker-archive-4                  2.296k ± 0%

ctr: connection error: desc = "transport: Error while dialing: dial unix /run/containerd/containerd.sock: connect: permission denied"
                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │           sec/op           │
SimpleImage_FetchSquashedContents/docker-archive-4                  26.14µ ± 0%

                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │            B/op            │
SimpleImage_FetchSquashedContents/docker-archive-4                 2.555Ki ± 0%

                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │         allocs/op          │
SimpleImage_FetchSquashedContents/docker-archive-4                   18.00 ± 0%
goos: linux
goarch: amd64
pkg: github.com/anchore/stereoscope/pkg/file
cpu: AMD EPYC 7763 64-Core Processor                
ctr: 
           │ .tmp/benchmark-ca96a68.txt │
           │           sec/op           │
TarIndex-4                  44.24µ ± 4%

           │ .tmp/benchmark-ca96a68.txt │
           │            B/op            │
TarIndex-4                 5.567Ki ± 0%

           │ .tmp/benchmark-ca96a68.txt │
           │         allocs/op          │
TarIndex-4                   93.00 ± 0%

pkg: github.com/anchore/stereoscope/test/integration
                                      │ .tmp/benchmark-ca96a68.txt │
                                      │           sec/op           │
SimpleImage_GetImage/docker-archive-4                  1.213m ± 7%

                                      │ .tmp/benchmark-ca96a68.txt │
                                      │            B/op            │
SimpleImage_GetImage/docker-archive-4                 270.4Ki ± 0%

                                      │ .tmp/benchmark-ca96a68.txt │
                                      │         allocs/op          │
SimpleImage_GetImage/docker-archive-4                  2.296k ± 0%

ctr: connection error: desc = "transport: Error while dialing: dial unix /run/containerd/containerd.sock: connect: permission denied"
                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │           sec/op           │
SimpleImage_FetchSquashedContents/docker-archive-4                  26.14µ ± 0%

                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │            B/op            │
SimpleImage_FetchSquashedContents/docker-archive-4                 2.555Ki ± 0%

                                                   │ .tmp/benchmark-ca96a68.txt │
                                                   │         allocs/op          │
SimpleImage_FetchSquashedContents/docker-archive-4                   18.00 ± 0%

@willmurphyscode willmurphyscode added the bug Something isn't working label Mar 6, 2026
@willmurphyscode willmurphyscode merged commit 78486e6 into main Mar 6, 2026
7 checks passed
@willmurphyscode willmurphyscode deleted the fix-cleanup-on-err branch March 6, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants