Nextcloud hangs when the main Active Directory server shuts down

Nextcloud version: 24.0.7
Operating system and version: Almalinux 8
Apache or nginx version: Apache 2.4.37
PHP version: 8.1.11

The issue you are facing: I have integrated my Nextcloud installation with an Active Directory server (Windows Server 2019 Standard) . I created a second Active Directory with the same Windows Server version and setup replication with my main Active Directory, so both servers to have the same data.

I went to LDAP/AD integration, clicked the Advanced button and entered the IP Address and Port of the backup Active Directory at fields Backup (Replica) Host and Backup (Replica) Port .

I shut down the main Active Directory and Nextcloud stopped responding (it was trying to load and then throwed a 504 error) .

It should have switched automatically to the replica Active Directory.

When i set the replica Active Directory as the main Active Directory, everything works fine.

I have seen ldap switch over to backup server does not work · Issue #14159 · nextcloud/server · GitHub , but:

a) It is not clear to me at which line to put the fix
b) I don’t want to apply such fix, since the file will be overwritten at future Nextcloud updates

Is this the first time you’ve seen this error? : Yes

Steps to replicate it:

  1. Enter the replica Active Directory IP at Backup (Replica) Host and the port at Backup (Replica) Port

  2. Shutdown the main Active Directory. Nextcloud will hang.

The output of your Nextcloud log in Admin > Logging:

Nothing relevant logged

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'HIDDEN INFORMATION',
  'passwordsalt' => 'HIDDEN INFORMATION',
  'secret' => 'HIDDEN INFORMATION',
  'trusted_domains' => 
  array (
    0 => 'MAIN DOMAIN',
    1 => 'MAIN IP',
    2 => 'SECONDARY DOMAIN',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'skeletondirectory' => '',
  'dbtype' => 'mysql',
  'version' => '24.0.7.1',
  'overwrite.cli.url' => 'https://MAIN DOMAIN',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'HIDDEN INFORMATION',
  'installed' => true,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'mail_from_address' => 'noreply',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'MAIN DOMAIN',
  'mail_smtpauthtype' => 'PLAIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'SMTP SERVER',
  'mail_smtpport' => '587',
  'mail_smtpsecure' => 'tls',
  'mail_smtpname' => 'USERNAME',
  'mail_smtppassword' => 'PASSWORD',
  'default_language' => 'en',
  'force_language' => 'en',
  'logtimezone' => 'Europe/Athens',
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' => 
  array (
    0 => 'HIDDEN INFORMATION',
    1 => 'HIDDEN INFORMATION',
    2 => 'HIDDEN INFORMATION',
    3 => 'HIDDEN INFORMATION',
    4 => 'HIDDEN INFORMATION',
    5 => 'HIDDEN INFORMATION',
    6 => 'HIDDEN INFORMATION',
    7 => 'HIDDEN INFORMATION',
    8 => 'HIDDEN INFORMATION',
    9 => 'HIDDEN INFORMATION',
    10 => 'HIDDEN INFORMATION',
    11 => 'HIDDEN INFORMATION',
    12 => 'HIDDEN INFORMATION',
    13 => 'HIDDEN INFORMATION',
    14 => 'HIDDEN INFORMATION',
    15 => 'HIDDEN INFORMATION',
    16 => 'HIDDEN INFORMATION',
    17 => 'HIDDEN INFORMATION',
    18 => 'HIDDEN INFORMATION',
    19 => 'HIDDEN INFORMATION',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
    0 => 'admin',
  ),
);

The output of your Apache/nginx/system log in /var/log/____:

Nothing relevant logged

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors.

Use a pastebin service if necessary.

Nothing relevant logged

Are you using the LDAP port or the global catalog port?

It’s because of some service dependencies,
check your NTP configuration first, if everything is all-right go to your main AD Server find Isaas.exe running in task manager, temporary disable it to check the environment;

I am using port 389 both for the main and the backup active directory.

Please note that only a single domain exists at the active directory setup.

The NTP configuration both at Nextcloud and the active directories is fine. Also all of them are at the same timezone.

As i have mentioned at my original message, when i set the secondary active directory as primary, everything works fine, users can authenticate without any problem.

Nextcloud just does not fall back to the secondary active directory.

Have you restarted PHP-FPM (if using the FastCGI version) or Apache (if using PHP core)? Nextcloud loads holds LDAP connection details during load.

Did you try what i said ? I am pretty Sure your Lightweight Directory Access Protocol not configured properly so nextcloud server still has dependencies on your previous ADDS