aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/subscription_adapter/postgresql.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-01-25 03:53:27 +1030
committerMatthew Draper <matthew@trebex.net>2016-01-30 03:46:37 +1030
commit16a6603956551703e3bbd06101c568a73bcdaa52 (patch)
treee11ead941c881d3a58956ee5f80e91e1702ac89c /actioncable/lib/action_cable/subscription_adapter/postgresql.rb
parenta928aa3d3f1e6f8780acc22d69f4d5d1f5917926 (diff)
downloadrails-16a6603956551703e3bbd06101c568a73bcdaa52.tar.gz
rails-16a6603956551703e3bbd06101c568a73bcdaa52.tar.bz2
rails-16a6603956551703e3bbd06101c568a73bcdaa52.zip
Synchronize the lazy setters in Server
They're all at risk of races on the first requests.
Diffstat (limited to 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb')
-rw-r--r--actioncable/lib/action_cable/subscription_adapter/postgresql.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb
index 3ce1bbed68..abaeb92e54 100644
--- a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb
+++ b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb
@@ -5,6 +5,11 @@ require 'thread'
module ActionCable
module SubscriptionAdapter
class PostgreSQL < Base # :nodoc:
+ def initialize(*)
+ super
+ @listener = nil
+ end
+
def broadcast(channel, payload)
with_connection do |pg_conn|
pg_conn.exec("NOTIFY #{pg_conn.escape_identifier(channel)}, '#{pg_conn.escape_string(payload)}'")
@@ -37,7 +42,7 @@ module ActionCable
private
def listener
- @listener ||= Listener.new(self)
+ @listener || @server.mutex.synchronize { @listener ||= Listener.new(self) }
end
class Listener < SubscriberMap