Fix the channel that never receives a value (#18139)

fix the channel that never receives a value
fix the code with the linter's recommendation by https://github.com/goharbor/harbor/blob/main/CONTRIBUTING.md#develop-build-and-test

Signed-off-by: iAklis <chenpinwei@gmail.com>
This commit is contained in:
Aklis 2023-05-19 09:17:46 +08:00 committed by GitHub
parent bf7c82b9a8
commit 6a79de761b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -82,7 +82,7 @@ func GetAnyKey(digests map[digest.Digest]io.ReadSeeker) (d digest.Digest) {
return
}
// GetAnyKeys ...
// GetKeys ...
func GetKeys(digests map[digest.Digest]io.ReadSeeker) (ds []digest.Digest) {
for d := range digests {
ds = append(ds, d)

View File

@ -57,6 +57,7 @@ func (s *RegistryCtl) Start() {
TLSConfig: common_http.NewServerTLSConfig(),
}
ctx := context.Background()
shutdown := make(chan struct{})
regCtl.RegisterOnShutdown(tracelib.InitGlobalTracer(ctx))
// graceful shutdown
go func() {
@ -65,6 +66,8 @@ func (s *RegistryCtl) Start() {
<-sig
context, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
defer close(shutdown)
log.Infof("Got an interrupt, shutting down...")
if err := regCtl.Shutdown(context); err != nil {
log.Fatalf("Failed to shutdown registry controller: %v", err)
@ -81,7 +84,7 @@ func (s *RegistryCtl) Start() {
} else {
err = regCtl.ListenAndServe()
}
<-ctx.Done()
<-shutdown
if err != nil {
log.Fatal(err)
}