I'm trying to implement a feature where a user will know if someone is online after they log in. I'm using Anycable for the WebSocket. When the user visits the website, WebSocket will add the user id to Redis and will delete if the user disconnects to the website. Now, after some time or if I refresh the website multiple times it throws an error "Subscribe error: Application error: ERR max number of clients reached". The website is deployed on heroku.
I commented the part of adding and deleting the user id to Redis and didn't throw any errors anymore.
def subscribed
stream_from "appearances_channel"
redis = Redis.new
puts user_id
online = true
puts online
online ? redis.set("user_#{user_id}_online", "1") : redis.del("user_#{user_id}_online")
ActionCable.server.broadcast "appearances_channel",
user_id: user_id,
online: online
end
def unsubscribed
redis = Redis.new
online = false
online ? redis.set("user_#{user_id}_online", "1") : redis.del("user_#{user_id}_online")
ActionCable.server.broadcast "appearances_channel",
user_id: user_id,
online: online
end
Error Log:
2019-08-06T13:26:37.867650+00:00 app[web.1]: [AnyCable sid=kn3TwGsIbbqA5AXX3UHWKp] RPC Disconnect: <AnyCable::DisconnectRequest: identifiers: "{\"__ltags__\":[\"ActionCable\",\"1\"],\"current_user\":\"1\"}", subscriptions: [], path: "/cable?id=1", headers: {"cookie"=>""}>
2019-08-06T13:26:37.867978+00:00 app[web.1]: [AnyCable sid=kn3TwGsIbbqA5AXX3UHWKp] [ActionCable] [1] Finished "/cable?id=1" [AnyCable] for at 2019-08-06 13:26:37 +0000 (Closed)
2019-08-06T13:26:38.817847+00:00 app[web.1]: [AnyCable sid=RN4~mA8EX6PmMO2tR83Ei6] RPC Connect: <AnyCable::ConnectionRequest: path: "/cable?id=1", headers: {"cookie"=>""}>
2019-08-06T13:26:38.818099+00:00 app[web.1]: [AnyCable sid=RN4~mA8EX6PmMO2tR83Ei6] Started "/cable?id=1" [AnyCable] for at 2019-08-06 13:26:38 +0000
2019-08-06T13:26:39.053969+00:00 app[web.1]: [AnyCable sid=RN4~mA8EX6PmMO2tR83Ei6] RPC Command: <AnyCable::CommandMessage: command: "subscribe", identifier: "{\"channel\":\"AppearanceChannel\"}", connection_identifiers: "{\"__ltags__\":[\"ActionCable\",\"1\"],\"current_user\":\"1\"}", data: "">
2019-08-06T13:26:39.054228+00:00 app[web.1]: 1
2019-08-06T13:26:39.054245+00:00 app[web.1]: true
2019-08-06T13:26:39.131043+00:00 app[web.1]: [AnyCable
sid=RN4~mA8EX6PmMO2tR83Ei6] ERR max number of clients reached
2019-08-06T13:26:39.131313+00:00 app[web.1]: E 2019-08-06T13:26:39.131Z context=node sid=RN4~mA8EX6PmMO2tR83Ei6 Subscribe error: Application error: ERR max number of clients reached