From 13f8189f2a6095991c660cb319b59eba10a69c09 Mon Sep 17 00:00:00 2001 From: Manish Tomar Date: Tue, 14 Aug 2018 13:10:56 -0700 Subject: [PATCH] fix memory leak introduced in PR #2648 context.App.repoRemover is single registry instance stored throughout app run. It was wrapped in another remover when processing each request. This remover happened to be remover got from previous request. This way every remover created was stored in infinite linked list causing memory leak. Fixing it by storing the wrapped remover inside the request context which will get gced when request context is gced. This was introduced in PR #2648. Signed-off-by: Manish Tomar --- registry/handlers/app.go | 2 +- registry/handlers/context.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 4cc47371..35b5504f 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -702,7 +702,7 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler { } // assign and decorate the authorized repository with an event bridge. - context.Repository, context.App.repoRemover = notifications.Listen( + context.Repository, context.RepositoryRemover = notifications.Listen( repository, context.App.repoRemover, app.eventBridge(context, r)) diff --git a/registry/handlers/context.go b/registry/handlers/context.go index e5d26768..7a67b604 100644 --- a/registry/handlers/context.go +++ b/registry/handlers/context.go @@ -25,6 +25,9 @@ type Context struct { // should be scoped to a single repository. This field may be nil. Repository distribution.Repository + // RepositoryRemover provides method to delete a repository + RepositoryRemover distribution.RepositoryRemover + // Errors is a collection of errors encountered during the request to be // returned to the client API. If errors are added to the collection, the // handler *must not* start the response via http.ResponseWriter.