• antirez's avatar
    Client should not block multiple times on the same key. · 4e6dd7bc
    antirez authored
    Sending a command like:
    
    BLPOP foo foo foo foo 0
    
    Resulted into a crash before this commit since the client ended being
    inserted in the waiting list for this key multiple times.
    This resulted into the function handleClientsBlockedOnLists() to fail
    because we have code like that:
    
        if (de) {
            list *clients = dictGetVal(de);
            int numclients = listLength(clients);
    
            while(numclients--) {
                listNode *clientnode = listFirst(clients);
    
                /* server clients here... */
            }
        }
    
    The code to serve clients used to remove the served client from the
    waiting list, so if a client is blocking multiple times, eventually the
    call to listFirst() will return NULL or worse will access random memory
    since the list may no longer exist as it is removed by the function
    unblockClientWaitingData() if there are no more clients waiting for this
    list.
    
    To avoid making the rest of the implementation more complex, this commit
    modifies blockForKeys() so that a client will be put just a single time
    into the waiting list for a given key.
    
    Since it is Saturday, I hope this fixes issue #801.
    4e6dd7bc
t_list.c 39.8 KB