You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/12/31 23:55:04 UTC

[GitHub] [pulsar-client-go] cckellogg commented on a change in pull request #154: [Issue #153] Fix handler memory leak

cckellogg commented on a change in pull request #154: [Issue #153] Fix handler memory leak
URL: https://github.com/apache/pulsar-client-go/pull/154#discussion_r362293342
 
 

 ##########
 File path: pulsar/internal/client_handlers.go
 ##########
 @@ -36,6 +36,13 @@ func (h *ClientHandlers) Add(c Closable) {
 	defer h.l.Unlock()
 	h.handlers[c] = true
 }
+
+func (h *ClientHandlers) Del(c Closable) {
+	h.l.Lock()
+	defer h.l.Unlock()
+	delete(h.handlers, c)
+}
+
 
 Review comment:
   The close method in this class will have to change otherwise there is a deadlock.
   
   We should make a copy of the handlers then release the lock and then call close on the list of handlers. Otherwise the one handler (producer or consumer) will try to call Del() and be deadlocked.
   
   Something like this should work
   
   func (h *ClientHandlers) Close() {
           h.l.Lock()
   	handlers := make([]Closable, 0, len(h.handlers))
   	for handler := range h.handlers {
   		handlers = append(handlers, handler)
   	}
   	h.l.Unlock()
   
   	for _, handler := range handlers {
   		handler.Close()
   	}
   }

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services