Skip to content

race condition in __wait_for_db_init() ? #13

Open
@jipanyang

Description

@jipanyang

Based on the description in https://redis.io/topics/notifications:
"
Because Redis Pub/Sub is fire and forget currently there is no way to use this feature if your application demands reliable notification of events, that is, if your Pub/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost.
"
It looks to me there is possibility the INIT_INDICATOR is set between client.get() and pubsub.psubscribe(pattern), the notification might get missed and pubsub.listen() will be blocked there, unless client buffers all notification from the moment of client.pubsub()

def __wait_for_db_init(self):
    client = self.redis_clients[self.CONFIG_DB]
    pubsub = client.pubsub()
    initialized = client.get(self.INIT_INDICATOR)
    if not initialized:
        pattern = "__keyspace@{}__:{}".format(self.db_map[self.CONFIG_DB]['db'], self.INIT_INDICATOR)
        pubsub.psubscribe(pattern)
        for item in pubsub.listen():

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stcheng@jipanyang

        Issue actions

          race condition in __wait_for_db_init() ? · Issue #13 · sonic-net/sonic-py-swsssdk