Repository navigation
Description
Description
tl;dr: This issue is a reopen of #2374 with more insights. In #4293 we fixed the predominant root cause for the issue - the non-graceful shutdown. However, the issue can still occur and the proxy cannot recover automatically from it leaking (losing track of) all the cached images in its storage.
We observed a new occurrence of #2374. Logs of the proxy
time="2024-10-04T06:21:24.616587724Z" level=info msg="redis not configured" go.version=go1.22.4 instance.id=305395bb-a130-4af9-9f1e-c3240f6769ea service=registry version=3.0.0-beta.1
time="2024-10-04T06:21:24.616627486Z" level=info msg="Starting upload purge in 58m0s" go.version=go1.22.4 instance.id=305395bb-a130-4af9-9f1e-c3240f6769ea service=registry version=3.0.0-beta.1
panic: unexpected end of JSON input
goroutine 1 [running]:
github.com/distribution/distribution/v3/registry/handlers.NewApp({0x1c03e20, 0xc0000c3e60}, 0xc0008ea488)
github.com/distribution/distribution/v3/registry/handlers/app.go:353 +0x1cc5
github.com/distribution/distribution/v3/registry.NewRegistry({0x1c03e20?, 0xc0000c2bd0?}, 0xc0008ea488)
github.com/distribution/distribution/v3/registry/registry.go:142 +0x56
github.com/distribution/distribution/v3/registry.init.func1(0x2734b00, {0xc0005919e0, 0x1, 0x1})
github.com/distribution/distribution/v3/registry/registry.go:111 +0x10a
github.com/spf13/cobra.(*Command).execute(0x2734b00, {0xc0005919a0, 0x1, 0x1})
github.com/spf13/[email protected]/command.go:987 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0x2734de0)
github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0xc0000061c0?)
github.com/spf13/[email protected]/command.go:1039 +0x13
main.main()
github.com/distribution/distribution/v3/cmd/registry/main.go:26 +0x1a
The logs from the instance before this panic occurs:
# ...
2024-10-03 15:43:54 time="2024-10-03T15:43:54.749227425Z" level=info msg="stopping server gracefully. Draining connections for 25s" go.version=go1.22.4 instance.id=5731de6f-05af-43a1-b44b-a3c1bf25e067 service=registry version=3.0.0-beta.1
2024-10-03 15:43:54 time="2024-10-03T15:43:54.750578013Z" level=fatal msg="error writing scheduler state: filesystem: write /var/lib/registry/scheduler-state.json: no space left on device"
As you can see from the logs, the disk space was exhausted.
When I checked, the /var/lib/registry/scheduler-state.json file was empty:
$ ls -la /var/lib/registry/scheduler-state.json
-rw-r--r-- 1 root root 0 Oct 3 15:43 /var/lib/registry/scheduler-state.json
$ cat /var/lib/registry/scheduler-state.json
This is a pretty bad state. Because the volume of the proxy is full with cached images. But the scheduler-state.json is empty and the proxy lost track of all these blobs. Hence, it won't be able to delete the blobs when the TTL expires.
The reason for the scheduler-state.json file to be empty seems to be the specific logic we have for writing a file:
distribution/registry/storage/driver/filesystem/driver.go
Lines 176 to 206 in 7ce129d
| func (d *driver) Writer(ctx context.Context, subPath string, append bool) (storagedriver.FileWriter, error) { | |
| fullPath := d.fullPath(subPath) | |
| parentDir := path.Dir(fullPath) | |
| if err := os.MkdirAll(parentDir, 0o777); err != nil { | |
| return nil, err | |
| } | |
| fp, err := os.OpenFile(fullPath, os.O_WRONLY|os.O_CREATE, 0o666) | |
| if err != nil { | |
| return nil, err | |
| } | |
| var offset int64 | |
| if !append { | |
| err := fp.Truncate(0) | |
| if err != nil { | |
| fp.Close() | |
| return nil, err | |
| } | |
| } else { | |
| n, err := fp.Seek(0, io.SeekEnd) | |
| if err != nil { | |
| fp.Close() | |
| return nil, err | |
| } | |
| offset = n | |
| } | |
| return newFileWriter(fp, offset), nil | |
| } |
We first truncate the file, then we write the new content. If we cannot write the new content, then the file is only truncated. Any new start of the proxy fails with
panic: unexpected end of JSON input because the truncated file does not contain a valid JSON document.
It should be possible to improve the logic for writing the file and prevent such type of issues. For example first writing the content to a new file and moving the new file to the place of the old one.
Reproduce
- Setup a proxy
- Make sure that there is no available disk space
- Stop the proxy process so that it tries to write to the
scheduler-state.jsonfile - Make sure that it cannot write to the
scheduler-state.jsonfile and leaves it in truncated state. - Make sure that any new start of the proxy fails with
panic: unexpected end of JSON input
Expected behavior
proxy shouldn't leave the scheduler-state.json file truncated when it cannot write to it due to no available disk space.
registry version
3.0.0-beta.1
Additional Info
No response
Activity
Fix: resolve issue distribution#4478 by using a temporary file for no…
Fix: resolve issue distribution#4478 by using a temporary file for no…
Fix: resolve issue distribution#4478 by using a temporary file for no…
Fix: resolve issue distribution#4478 by using a temporary file for no…
Fix: resolve issue #4478 by using a temporary file for non-append wri…
LiuShuaiyi commentedon Jun 13, 2025
@onporat Thanks for sending the PR to fix this issue. I have 2 small questions about the pull request: https://github.com/distribution/distribution/pull/4624/files#r2146077767. PTAL.
ialidzhikov commentedon Jul 28, 2025
This issue is hopefully fixed with #4624.
@milosgajdos , is it possible to cut a new release so that we can adopt the bugfix?
milosgajdos commentedon Aug 5, 2025
I need to go through PR backlog first, but yeah I'd love to cut a release soon!
ialidzhikov commentedon Sep 3, 2025
@milosgajdos , any news? We are looking forward to adopt a new release to adopt the fix for this issue.
ialidzhikov commentedon Oct 6, 2025
Hi @milosgajdos ,
Is there any progress with a new patch release for the Distribution project?
milosgajdos commentedon Oct 17, 2025
I'd like to but $DAY_JOB has kept me busy and free work for CNCF has low priority
ningmingxiao commentedon Feb 1, 2026
pr #4774 may fix the data is empty
ialidzhikov commentedon Apr 21, 2026
I am closing this issue as it appears to be fixed in 3.1.0 with #4624.
I will reopen if we observe it again with 3.1.0.
kastl-ars commentedon Apr 29, 2026
Hi everyone, I just saw my registry hitting this error. I upgraded to 3.1.0 but still see this. Should upgrading fix the issue, i.e. repair the underlying problems, or do I need to manually clean up? Or is it simply not properly fixed?
milosgajdos commentedon Apr 29, 2026
#4860
kastl-ars commentedon Apr 30, 2026
Care to elaborate? Seems like this is not released yet, any ETA on a new release?
milosgajdos commentedon Apr 30, 2026
we'll do a patch release soon; no ETA, you can pull the
:latesttag from distirbution namespace or GHkastl-ars commentedon May 1, 2026
Just tested with the 3.1.1 release on ghcr, no change, still panics...
milosgajdos commentedon May 1, 2026
what storage driver are you? We need more details here as all of them bring their own idiosyncrasies
I'm reopening this issue
ialidzhikov commentedon May 1, 2026
I don't know how #4860 is related.
@kastl-ars , you have to clean up the already corrupted
scheduler-state.json. The fix in #4624 only prevents new occurrences of the issue. It does not recover from already broken (empty)scheduler-state.jsonfile.tl;dr: @kastl-ars I think the issue is fixed. Your confusion comes from your expectation that the fix will also recover the broken (empty)
scheduler-state.jsonfile. Just fix manually thescheduler-state.jsonfile (for example delete it and delete the cached content) and you should not hit the same issue again.@dimitar-kostadinov was testing 3.1.0 version on our side. He was able to confirm that this issue is fixed with #4624.
But he found other issues with the scenario when the proxy's volume disk space gets exhausted.
He found that image pulls from the proxy fail.
kubelet events:
proxy log:
Most likely he will open a new issue with these findings but we wanted to gain more insights.
milosgajdos commentedon May 1, 2026
Yeah I mistakenly attributed wrong PR
kastl-ars commentedon May 1, 2026
Thanks, that was my guess, hence my question a little up in the comments. Will try to clean this up (need to find a way to access the PV with the pod immediately crashing, but I'll find a way)