Sentinel: rewrite callback chain removing instances with shared links

Otherwise pending commands callbacks will fire with a reference that no
longer exists.
This commit is contained in:
antirez 2015-05-14 13:39:26 +02:00
parent 05dbc82005
commit 5a0516b5b9

View File

@ -969,7 +969,23 @@ instanceLink *releaseInstanceLink(instanceLink *link, sentinelRedisInstance *ri)
link->refcount--;
if (link->refcount != 0) {
if (ri) {
/* TODO: run the callbacks list and rebind. */
/* This instance may have pending callbacks in the hiredis async
* context, having as 'privdata' the instance that we are going to
* free. Let's rewrite the callback list, directly exploiting
* hiredis internal data structures, in order to bind them with
* a callback that will ignore the reply at all. */
redisCallback *cb;
redisCallbackList *callbacks = &link->cc->replies;
cb = callbacks->head;
while(cb) {
if (cb->privdata == ri) {
printf("HERE\n");
cb->fn = sentinelDiscardReplyCallback;
cb->privdata = NULL; /* Not strictly needed. */
}
cb = cb->next;
}
}
return link; /* Other active users. */
}