]> git.saurik.com Git - redis.git/commit
Client should not block multiple times on the same key.
authorantirez <antirez@gmail.com>
Sat, 1 Dec 2012 11:26:07 +0000 (12:26 +0100)
committerantirez <antirez@gmail.com>
Sun, 2 Dec 2012 19:43:07 +0000 (20:43 +0100)
commit4e6dd7bc86ccb0dcf47c9a6e712ff51a28162cf6
tree91586b3b471667941ce44f7c8a7ed8d038be1e7c
parentf50e658455f6455ac443e185e5fc738ef15093b3
Client should not block multiple times on the same key.

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.
src/t_list.c