Fix race conditions in pubsub #966
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So... remember this: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 1 minute(s) ?
After building lettuce with a patch to include command name in the timeout message it turned out that the timeouting command is
SUBSCRIBE, which was weird. Until I looked at the code that does the subscription.These seems to be buggy:
redis4cats/modules/streams/src/main/scala/dev/profunktor/redis4cats/pubsub/internals/Subscriber.scala
Lines 35 to 42 in 63532d6
redis4cats/modules/streams/src/main/scala/dev/profunktor/redis4cats/pubsub/internals/Subscriber.scala
Lines 53 to 62 in 63532d6
state.getfrom aRefand expect that state to hold while you go on to perform side-effects..unNoneis highly questionable, it just filters outNone's, I guess this was intended to beunNoneTerminate.Topicshared between multiple streams, but eachsubscribegets it's own redis listener andDispatcher? Why?So I rewrote the logic to:
AtomicCellstate maps for channels and patterns.Dispatcherfirst time someone subscribes to channel or pattern.Streamis terminated.unsubscribefinishes allStreams.I also changed the return type of
publishto match the type from Lettuce.@yisraelU I would appreciate you double-checking the logic here.