This is a Rails 7 app using REDIS for pubsub, hosted on Heroku ("Heroku Data for Redis" add on). This also happens locally (when I set the maxclients down to 20, like is set for the Heroku instance)
trap(:TERM) { shutdown }
pool.with do |conn|
conn.subscribe(@stream) do |listener|
register_subscription_callback(listener)
register_message_callback(listener)
register_unsubscription_callback(listener)
end
end
I want to allow the caller to abort the listening, so I'm trying to change it like this:
pool.with do |conn|
until abort_signal.set?
@logger.debug("listening for pubsub events for 5 seconds")
conn.subscribe_with_timeout(5, @stream) do |listener|
register_subscription_callback(listener)
register_message_callback(listener)
register_unsubscription_callback(listener)
end
end
end
However, after 20 loops (on the 21st attempt), I get an error
RedisClient::CommandError: ERR max number of clients reached (RedisClient::CommandError)
Alternatively, I've tried putting my while loop above the withdrawal from the connection pool:
until abort_signal.set?
pool.with do |conn|
@logger.debug("listening for pubsub events for 5 seconds")
conn.subscribe_with_timeout(5, @stream) do |listener|
register_subscription_callback(listener)
register_message_callback(listener)
register_unsubscription_callback(listener)
end
end
end
I've also tried removing the connection pool altogether, but still experience the issue.
I've also tried just using the recipe from your README
redis = Redis.new(reconnect_attempts: 0)
while true
redis.subscribe_with_timeout(5, "news") do |on|
on.message do |channel, message|
# ...
end
end
end
and still experienced the issue.
Can you help me to get an interruptable subscribe for PUBSUB events?
If via subscribe_with_timeout, what is the underlying reason for my error?
This is a Rails 7 app using REDIS for pubsub, hosted on Heroku ("Heroku Data for Redis" add on). This also happens locally (when I set the maxclients down to 20, like is set for the Heroku instance)
Our code sets up REDIS like this:
We listen for pubsub like this:
I want to allow the caller to abort the listening, so I'm trying to change it like this:
However, after 20 loops (on the 21st attempt), I get an error
Alternatively, I've tried putting my
while
loop above the withdrawal from the connection pool:I've also tried removing the connection pool altogether, but still experience the issue.
I've also tried just using the recipe from your README
and still experienced the issue.
Can you help me to get an interruptable subscribe for PUBSUB events? If via
subscribe_with_timeout
, what is the underlying reason for my error?Thank you