GoogleCloudPlatform / gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Apache License 2.0
805 stars 112 forks source link

Recursive flag causes failure in Pub Sub endpoint #70

Closed AdamHawtin closed 2 years ago

AdamHawtin commented 2 years ago

Setting the recursive option to true when triggering the GCR cleaner server from the Pub Sub causes it to fail. I've observed this when deployed in cloud run and also replicated it running the server locally.

Resulting log message:

{"error":"failed to list child repositories for \"\": failed to fetch all repositories from registry europe-west2-docker.pkg.dev: context canceled","message":"failed to clean","severity":"ERROR","time":"2022-03-18T08:54:36Z"}

I believe this is because in the Pub Sub handler, the server.clean function is handed off to a goroutine while the original request is completed, closing the request context while server.clean is still working. However, the call to gcrremote.Catalog in cleaner.ListChildRepositories requires the context to still be open to succeed.