Explicitly close notification connection channel

I don't believe that closing Fiber channels are strictly necessary
but it doesn't hurt to do.
This commit is contained in:
syeopite 2025-06-01 12:43:55 -07:00
parent ded671ea6d
commit 25168958e8
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 8 additions and 1 deletions

View File

@ -152,6 +152,7 @@ def create_notification_stream(env, topics, connection_channel)
end end
rescue ex rescue ex
ensure ensure
connection.close
connection_channel.send({false, connection}) connection_channel.send({false, connection})
end end
end end

View File

@ -32,7 +32,13 @@ class Invidious::Jobs::NotificationJob < Invidious::Jobs::BaseJob
def begin def begin
connections = [] of ::Channel(PQ::Notification) 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 # hash of channels to their videos (id+published) that need notifying
to_notify = Hash(String, Set(VideoNotification)).new( to_notify = Hash(String, Set(VideoNotification)).new(