From: Tim Beale Date: Wed, 17 Oct 2018 01:41:12 +0000 (+1300) Subject: join: LDAP connection to remote DC can timeout in large join X-Git-Tag: tdb-1.3.17~1296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8ea16a3fb6d8ad9b738e8e71adc07079a292079;p=thirdparty%2Fsamba.git join: LDAP connection to remote DC can timeout in large join When joining a very large domain (e.g. 100K users), the replication can take so long that the LDAP connection to the remote DC times out. This patch avoids the problem by adding in a sanity-check after the replication finishes that the LDB connection is still alive. If not, then we reconnect. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13612 Signed-off-by: Tim Beale Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/join.py b/python/samba/join.py index 3869947f737..6a9c3b9807f 100644 --- a/python/samba/join.py +++ b/python/samba/join.py @@ -1020,6 +1020,27 @@ class DCJoinContext(object): else: ctx.local_samdb.transaction_commit() + # A large replication may have caused our LDB connection to the + # remote DC to timeout, so check the connection is still alive + ctx.refresh_ldb_connection() + + def refresh_ldb_connection(ctx): + try: + # query the rootDSE to check the connection + ctx.samdb.search(scope=ldb.SCOPE_BASE, attrs=[]) + except ldb.LdbError as e: + (enum, estr) = e.args + + # if the connection was disconnected, then reconnect + if (enum == ldb.ERR_OPERATIONS_ERROR and + 'NT_STATUS_CONNECTION_DISCONNECTED' in estr): + ctx.logger.warning("LDB connection disconnected. Reconnecting") + ctx.samdb = SamDB(url="ldap://%s" % ctx.server, + session_info=system_session(), + credentials=ctx.creds, lp=ctx.lp) + else: + raise DCJoinException(estr) + def send_DsReplicaUpdateRefs(ctx, dn): r = drsuapi.DsReplicaUpdateRefsRequest1() r.naming_context = drsuapi.DsReplicaObjectIdentifier()