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

Stop proxy scheduler on system exit #4293

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dimitar-kostadinov
Copy link
Contributor

@dimitar-kostadinov dimitar-kostadinov commented Mar 5, 2024

For pull through cache registry with configured TTL, a scheduler responsible for blobs garbage collection is started here: registry/proxy/proxyregistry.go#L109, but its Stop method is never invoked.

Scheduler state is written to scheduler-state.json if a state change is detected every 5 seconds.
When terminating the registry process, this can result in an inconsistent/corrupted scheduler-state.json:

  • recent state changes are not saved at all
  • scheduler-state.json has been truncated, but no new content has been written

This PR explicitly invokes scheduler Stop method on SIGINT & SIGTERM to ensure that scheduler state is preserved.

Fixes #2374

Copy link
Member

@milosgajdos milosgajdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I've overloooked something this LGTM. PTAL @thaJeztah

registry/registry.go Outdated Show resolved Hide resolved
Comment on lines +214 to +217
type Closer interface {
// Close release all resources used by this object
Close() error
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly wondering if we must define our own interface for this, or if io.Closer (same signature) would do 🤔

However, looking at the changes in this PR, it looks like we're differentiating the "proxy-registry" here. Usually I'm for "small interfaces", but I did notice there's a TODO for the Repository interface as a whole, so wondering if we should go that direction instead, and expand the Repository interface to require a Close() method?

distribution/registry.go

Lines 116 to 118 in bc6e81e

// TODO(stevvooe): Must add close methods to all these. May want to change the
// way instances are created to better reflect internal dependency
// relationships.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly wondering if we must define our own interface for this, or if io.Closer (same signature) would do 🤔

I was thinking about this exactly, but I figured at the time it'd be semantically confusing 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly wondering if we must define our own interface for this, or if io.Closer (same signature) would do 🤔

I agree with @milosgajdos. I also prefer to do not use io.Closer as the registry is not an IO resource, it is a different abstraction.


@thaJeztah , thanks for noticing the TODO. Actually, we don't have a strong opinion on the topic. We are at most familiar with the proxy registry codebase and we are using the proxy scenario only. With this PR our main goal is to fix #2374 and not do design/redesign the Repository interface. If you as a maintainer have a strong opinion that this should instead added in the Repository interface instead, we can do it. I think we are not that familiar with all of the existing codebase to decide whether the other Repository implementations need to close as well. The proxyRegistry needs such Close method for sure to be able to stop the scheduler (which saves the scheduler-state.json file).

@Jamstah
Copy link
Collaborator

Jamstah commented May 1, 2024

This now conflicts because #4338 got merged.

Should probably move the OnExit call from a defer into the new registry shutdown method.

@milosgajdos
Copy link
Member

@dimitar-kostadinov can you rebase

Signed-off-by: Dimitar Kostadinov <dimitar.kostadinov@sap.com>
Signed-off-by: Dimitar Kostadinov <dimitar.kostadinov@sap.com>
Signed-off-by: Dimitar Kostadinov <dimitar.kostadinov@sap.com>
serveErr := make(chan error)

// Start serving in goroutine and listen for stop signal in main thread
go func() {
serveErr <- registry.server.Serve(ln)
}()
defer func(app *handlers.App) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we now move this into registry.Shutdown so its with other shutdown actions?

I expect if an embedded registry is shutdown, closing this would also be appropriate.

registry/handlers/app.go Show resolved Hide resolved
@milosgajdos milosgajdos added this to the Registry/3.0.0 milestone May 4, 2024
Signed-off-by: Dimitar Kostadinov <dimitar.kostadinov@sap.com>
@milosgajdos milosgajdos requested a review from Jamstah May 7, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api area/proxy Related to registry as a pull-through cache
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic: unexpected end of JSON input
5 participants