Skip to content

Commit d9cac6f

Browse files
committed
fix: properly close broadcast channel to prevent memory leak
With a large number of requesting clients, the software keeps open an evenly large number of client structs and broadcastChannels filled with certificates. This is due to the broadcastHandler goroutine waiting for new elements to arrive in the channel. Since that does not happen, the client struct will not be freed and thus heap memory keeps piling up. In my case the tool used up ~3-4 GB of memory after 228 days of runtime with a single client that connected and disconnected frequently.
1 parent 9b866d5 commit d9cac6f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

internal/web/broadcastmanager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func (bm *BroadcastManager) unregisterClient(c *client) {
3434
bm.clients[len(bm.clients)-1] = nil
3535
bm.clients = bm.clients[:len(bm.clients)-1]
3636

37+
// Close the broadcast channel of the client, otherwise this leads to a memory leak
38+
close(c.broadcastChan)
39+
3740
break
3841
}
3942
}

0 commit comments

Comments
 (0)