From 393c4428336e507d4448fd81d96a16124db83dce Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@openldap.org>
Date: Thu, 1 Nov 2012 08:36:28 -0700
Subject: [PATCH] ITS#7427 fix for spurious old entries

---
 servers/slapd/syncrepl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c
index 7c07b90873..dec190da0f 100644
--- a/servers/slapd/syncrepl.c
+++ b/servers/slapd/syncrepl.c
@@ -112,6 +112,7 @@ typedef struct syncinfo_s {
 	int			si_logstate;
 	int			si_got;
 	int			si_strict_refresh;	/* stop listening during fallback refresh */
+	int			si_too_old;
 	ber_int_t	si_msgid;
 	Avlnode			*si_presentlist;
 	LDAP			*si_ld;
@@ -935,8 +936,10 @@ do_syncrep2(
 										si->si_ridtxt, syncCookie.ctxcsn->bv_val, bdn.bv_val );
 									ldap_controls_free( rctrls );
 									rc = 0;
+									si->si_too_old = 1;
 									goto done;
 								}
+								si->si_too_old = 0;
 								break;
 							}
 						}
@@ -976,6 +979,13 @@ do_syncrep2(
 						}
 						assert( punlock < 0 );
 						punlock = i;
+					} else if (si->si_too_old) {
+						bdn.bv_val[bdn.bv_len] = '\0';
+						Debug( LDAP_DEBUG_SYNC, "do_syncrep2: %s CSN too old, ignoring (%s)\n",
+							si->si_ridtxt, bdn.bv_val, 0 );
+						ldap_controls_free( rctrls );
+						rc = 0;
+						goto done;
 					}
 					op->o_controls[slap_cids.sc_LDAPsync] = &syncCookie;
 				}
@@ -1426,6 +1436,8 @@ do_syncrepl(
 			ldap_pvt_thread_yield();
 	}
 
+	si->si_too_old = 0;
+
 	if ( si->si_ctype < 1 ) {
 		goto deleted;
 	}
-- 
GitLab