From 0e5716da1adef46cbc12b169fce1e3b2bc713e2a Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Aug 2016 16:42:54 +0100 Subject: [PATCH] Add TODO explaining why the mutex storage is bad and what a better solution is --- src/github.com/matrix-org/go-neb/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/github.com/matrix-org/go-neb/api.go b/src/github.com/matrix-org/go-neb/api.go index b06f663..e0708a1 100644 --- a/src/github.com/matrix-org/go-neb/api.go +++ b/src/github.com/matrix-org/go-neb/api.go @@ -222,6 +222,9 @@ func (s *configureServiceHandler) getMutexForServiceID(serviceID string) *sync.M defer s.mapMutex.Unlock() m := s.mutexByServiceID[serviceID] if m == nil { + // XXX TODO: There's a memory leak here. The amount of mutexes created is unbounded, as there will be 1 per service which are never deleted. + // A better solution would be to have a striped hash map with a bounded pool of mutexes. We can't live with a single global mutex because the Register() + // function this is protecting does many many HTTP requests which can take a long time on bad networks and will head of line block other services. m = &sync.Mutex{} s.mutexByServiceID[serviceID] = m }