diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 516b0a6e..d72468f1 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -152,6 +152,7 @@ def create_notification_stream(env, topics, connection_channel) end rescue ex ensure + connection.close connection_channel.send({false, connection}) end end diff --git a/src/invidious/jobs/notification_job.cr b/src/invidious/jobs/notification_job.cr index 968ee47f..48e4eec2 100644 --- a/src/invidious/jobs/notification_job.cr +++ b/src/invidious/jobs/notification_job.cr @@ -32,7 +32,13 @@ class Invidious::Jobs::NotificationJob < Invidious::Jobs::BaseJob def begin connections = [] of ::Channel(PQ::Notification) - PG.connect_listen(pg_url, "notifications") { |event| connections.each(&.send(event)) } + PG.connect_listen(pg_url, "notifications") do |event| + connections.each do |channel| + channel.send(event) + rescue Channel::ClosedError + # Notification stream was closed. + end + end # hash of channels to their videos (id+published) that need notifying to_notify = Hash(String, Set(VideoNotification)).new(