From 5a0516b5b96b7bbd16c1942b281c798f3db03630 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 14 May 2015 13:39:26 +0200 Subject: Sentinel: rewrite callback chain removing instances with shared links Otherwise pending commands callbacks will fire with a reference that no longer exists. --- src/sentinel.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sentinel.c b/src/sentinel.c index 57d5fd27d..0d33d8219 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -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. */ } -- cgit v1.2.1