Redis stops calling "messageReceiver" closure/callback
I am using Redis in pub/sub mode. And I subscribed to my channel using the following method:
subscribe(to channels: RedisChannelName..., messageReceiver receiver: @escaping RedisSubscriptionMessageReceiver, onSubscribe subscribeHandler: RedisSubscriptionChangeHandler? = nil, onUnsubscribe unsubscribeHandler: RedisSubscriptionChangeHandler? = nil)
However at some point of uptime (usually after 60-90 minutes) Redis stops calling closure I passed as messageReceiver
param. And also onUnsubscribe
closure was not called in this case too. And note that I never called the app.redis.unsubscribe()
method in my code.
Expected behavior
- Redis keeps subscription alive during all the uptime.
-
messageReceiver
closure/callback is called each timePUBLISH
command sent
Actual behavior
- Redis stops calling closure I passed as
messageReceiver
- 1.1 There are no logs
Redis: Incoming message
after 2021-11-19 08:44:34 (See attached logs) PubSubLogs.txt
-
onUnsubscribe
closure was not called in this case -
NUMSUB
(app.redis.subscriberCount
) command returns the result indicating that there are no subscribers: [dealoger,0]
Steps to reproduce
- Deploy microservices that uses Redis in pub/sub mode
- 1.1
app.redis.configuration = try .init(url: redisUrl)
- 1.2
try? app.boot()
- 1.3
app.redis.subscribe(to: "dealoger") { [weak self] (channel, message) in self?.app.logger.info("Redis: Incoming message") } onSubscribe: { [weak self] subscriptionKey, currentSubscriptionCount in self?.app.logger.info("REDIS: on subscribe \(currentSubscriptionCount)") } onUnsubscribe: { [weak self] subscriptionKey, currentSubscriptionCount in self?.app.logger.error("REDIS: on unsubscribe \(currentSubscriptionCount)") } .whenComplete { [weak self] in switch $0 { case .success(): self?.app.logger.info("REDIS: Successfully subscribed to Dealoger channel") case .failure(let error): self?.app.logger.error("REDIS: Failed to subscribe to Dealoger channel: \(error)") } }
- 1.4 Setup pinging to avoid closing connection with Redis: I used
app.redis.send(command: "ping")
Also I tried to implement something like 'pinging subscription' (Usedapp.redis.publish("string", to: "dealoger")
to send some simple data each second). However this does not help to fix the issue.
- Wait about 60-90 minutes. Then send PUBLISH command to the channel.
- 2.1 Check whether
messageReceiver
closure is called
RediStack version/commit hash
Redis v4.4.0 RediStack v1.2.0
swift --version
)
Swift Version (output of swift-driver version: 1.26.9 Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1) Target: x86_64-apple-macosx11.0
uname -a
)
OS version (output of Ubuntu 18.04.4 LTS
We are using Docker to build our images: vapor/ubuntu:18.04
I was not able to reproduce this issue on my MacBook