Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.3.x] Fix memory leak in notification bus #7164

Merged
merged 1 commit into from Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions atc/db/notifications_bus.go
Expand Up @@ -166,6 +166,11 @@ func (m *notificationsMap) unregister(channel string, notify chan bool) {
defer m.Unlock()

delete(m.notifications[channel], notify)

// Note: we don't call empty since we already acquired the lock.
if len(m.notifications[channel]) == 0 {
delete(m.notifications, channel)
}
}

func (m *notificationsMap) each(f func(chan bool)) {
Expand Down
11 changes: 11 additions & 0 deletions atc/db/notifications_bus_test.go
Expand Up @@ -217,6 +217,17 @@ var _ = Describe("NotificationBus", func() {
Eventually(b).Should(Receive(Equal(false)))
})
})

Context("when one of the listeners unlistens", func() {
BeforeEach(func() {
bus.Unlisten("some-channel", a)
})

It("should still send notifications to the other listeners", func() {
c <- &pq.Notification{Channel: "some-channel"}
Eventually(b).Should(Receive(Equal(true)))
})
})
})

Context("when there are multiple listeners on different channels", func() {
Expand Down