PSYNC2: fix master cleanup when caching it.

The master client cleanup was incomplete: resetClient() was missing and
the output buffer of the client was not reset, so pending commands
related to the previous connection could be still sent.

The first problem caused the client argument vector to be, at times,
half populated, so that when the correct replication stream arrived the
protcol got mixed to the arugments creating invalid commands that nobody
called.

Thanks to @yangsiran for also investigating this problem, after
already providing important design / implementation hints for the
original PSYNC2 issues (see referenced Github issue).

Note that this commit adds a new function to the list library of Redis
in order to be able to reset a list without destroying it.

Related to issue #3899.
This commit is contained in:
antirez
2017-04-27 17:04:07 +02:00
parent 8c4b0f411f
commit 806905627c
3 changed files with 20 additions and 7 deletions

View File

@ -52,10 +52,8 @@ list *listCreate(void)
return list;
}
/* Free the whole list.
*
* This function can't fail. */
void listRelease(list *list)
/* Remove all the elements from the list without destroying the list itself. */
void listEmpty(list *list)
{
unsigned long len;
listNode *current, *next;
@ -68,6 +66,16 @@ void listRelease(list *list)
zfree(current);
current = next;
}
list->head = list->tail = NULL;
list->len = 0;
}
/* Free the whole list.
*
* This function can't fail. */
void listRelease(list *list)
{
listEmpty(list);
zfree(list);
}