From 00f72ef20668d9d048edc32dcd54c96006038a54 Mon Sep 17 00:00:00 2001 From: Fernando Barbosa Date: Tue, 27 Mar 2018 19:19:22 -0300 Subject: [PATCH] Fix EventStreamSSE Memory Leak The `Config.Services.Pubsub.Subscribe` is being initialized with the global Gin Context. This causes the publisher object to [hang at line 58](https://github.com/cncd/pubsub/blob/master/pub.go#L58) and the goroutine remains opened indefinetly, which can be a source of memory leak. Setting it to the locally defined ctx object correctly causes the goroutine to close when the function exits due to the deferred close. See https://discourse.drone.io/t/memory-leak-on-drone-server/1884 for further information. --- server/stream.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stream.go b/server/stream.go index 2e202989f..6dd19a9ba 100644 --- a/server/stream.go +++ b/server/stream.go @@ -78,7 +78,7 @@ func EventStreamSSE(c *gin.Context) { go func() { // TODO remove this from global config - Config.Services.Pubsub.Subscribe(c, "topic/events", func(m pubsub.Message) { + Config.Services.Pubsub.Subscribe(ctx, "topic/events", func(m pubsub.Message) { name := m.Labels["repo"] priv := m.Labels["private"] if repo[name] || priv == "false" {