Severe login delay with IMAP user authentication

Nextcloud version: 12.0.2
Operating system and version: Debian GNU/Linux 9.1 (Stretch)
Apache or nginx version: nginx 1.10.3
PHP version: PHP 7.0.19
Is this the first time you’ve seen this error?:

Yes, I have an older, parallel ownCloud 9.1 installation with the same setup, there we don’t experience such issues.

Can you reliably replicate it? (If so, please outline steps):

Yes.

It doesn’t seem to matter whether Apache or nginx is used.

The issue you are facing:

We experience a very long delay on initial login when using the OC_User_Imap authentication backend with Dovecot. After filling in the username and password, it can take a user over 50 seconds to see the full Files app.

It seems that for all JS/CSS/images (asset) files, an IMAP authentication is performed every single time. These authentications are also weirdly 2–3 seconds apart?

Of course, once everything is loaded, the browser doesn’t retrieve the asset files anymore and everything is fast and responsive again.

The output of your Nextcloud log in Admin > Logging:

There are no relevant log entries, as login proceeds fine.

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

<?php
$CONFIG = array (
  'instanceid' => 'ocizsoy6yzas',
  'passwordsalt' => 'REMOVED',
  'secret' => 'REMOVED',
  'trusted_domains' => 
  array (
    0 => 'cloud.domain.tld',
  ),
  'datadirectory' => '/srv/www/cloud.domain.tld/data',
  'overwrite.cli.url' => 'https://cloud.domain.tld',
  'dbtype' => 'pgsql',
  'version' => '12.0.2.0',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'REMOVED',
  'filelocking.enabled' => true,
  'installed' => true,
  'mail_from_address' => 'noreply',
  'mail_smtpmode' => 'php',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_domain' => 'dmain.tld',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'user_backends' => 
  array (
    0 => 
    array (
      'class' => 'OC_User_IMAP',
      'arguments' => 
      array (
        0 => '{imap.domain.tld:993/imap/ssl}',
      ),
    ),
  ),
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

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

The log file linked here shows the HTTP requests interleaved with IMAP authentication requests to be able see the interplay: https://paste.debian.net/983668/.

Should I convert this into a Github issue instead?

Worth to try. Maybe you’ll get more response there