Skip to content

Commit

Permalink
fix memory leak introduced in PR distribution#2648
Browse files Browse the repository at this point in the history
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 distribution#2648.

Signed-off-by: Manish Tomar <[email protected]>
  • Loading branch information
manishtomar authored and cquon committed Aug 31, 2018
1 parent 5cf595c commit 371db30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion registry/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,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))
Expand Down
3 changes: 3 additions & 0 deletions registry/handlers/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 371db30

Please sign in to comment.