[Bug]: Idle persistent Redis connection dropped by the network: "Connection lost" on pconnect, then NOAUTH and a 500 on the first requests
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 32/100
Piste de recherche
The failing call is the persistent branch of pconnect in lib/private/RedisFactory.php (around line 104), with the NOAUTH errors surfacing from lib/private/Memcache/Redis.php. Start by reading how RedisFactory opens and reuses persistent connections and where the redis.persistent config key is read. Done would mean a reproducible test for a dead persistent connection, plus a decision on whether to add a keepalive config key or a reconnect-and-authenticate path; the maintainers have not yet chosen between them.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
⚠️ This issue respects the following points: ⚠️
- This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug.
- This issue is not already reported on Github OR solved at the Community Help Forum (I searched the issues of nextcloud/server and phpredis for
pconnect, "Connection lost",NOAUTHandredis.persistent). - I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (33.0.11, the latest 33.x release.)
- I agree to follow Nextcloud's Code of Conduct.
- I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description
RedisFactory opens persistent Redis connections (redis.persistent defaults to true) and never enables TCP keepalive on them. When something between PHP and Redis drops an idle connection without sending a reset (Docker Swarm's virtual IPs do after 15 minutes, some cloud load balancers after a few minutes), the php-fpm worker that holds that connection fails its next request:
RedisException: Connection lost, thrown byRedis->pconnect()atlib/private/RedisFactory.php(the$persistentbranch),- then, in the same request, many
RedisException: NOAUTH Authentication required.from later cache calls (Memcache\Redis::get), and the request ends with a 500 "Internal Server Error".
So the instance returns 500 to the first requests that reach workers with a stale connection, and recovers by itself once each worker has reconnected. It shows on instances with little traffic, since every worker's connection is idle for more than the timeout.
Two points look like Nextcloud's side:
- There is no way to enable
SO_KEEPALIVEon these connections.OPT_TCP_KEEPALIVEexists in phpredis (6.3.0 here) but is not used, andssl_contextis handled as a TLS context, so a socket option cannot be passed there. - After
Connection lostonpconnect, the failed request goes on using the Redis cache and getsNOAUTH, instead of reconnecting and authenticating again. I could not isolate this second point from the first one.
The redis.persistent system config key that controls this is read in RedisFactory.php but not documented (the draft PR #61976 lists this as a to-do).
Steps to reproduce
- Nextcloud 33.0.11 behind php-fpm, Redis with a password (
'redis' => ['host' => ..., 'password' => ..., 'port' => 6379]),memcache.distributedandmemcache.lockingon Redis, defaultredis.persistent. - Put a connection-tracking proxy in the path that drops idle connections after N minutes (Docker Swarm: connect to a service through its virtual IP).
- Send enough requests in parallel to start all php-fpm workers, so each opens its persistent connection.
- Send no request for longer than N minutes (17 minutes with Swarm).
- Send requests again (
/login): the first ones, one per worker holding a dead connection, return 500 and log the two exceptions above. Later requests return 200.
Measured with a plain phpredis client on the same network, no keepalive: an idle connection through the Swarm virtual IP is dead after 20 minutes; the same connection made straight to the Redis proxy or to a Redis node is alive. With $redis->setOption(\Redis::OPT_TCP_KEEPALIVE, true) called after connect() and net.ipv4.tcp_keepalive_time=300 in the container, the connection is alive after 20 minutes. Calling setOption before connect() has no effect.
Expected behavior
Either an option to enable TCP keepalive on the Redis connections (a config key read by RedisFactory, set after the connection is opened), or a reconnect with authentication when a persistent connection is found dead, so the request does not fail.
Nextcloud Server version
33
Operating system
Debian/Ubuntu (official nextcloud:33-fpm Docker image)
PHP engine version
PHP 8.4
Web server
Nginx
Database engine version
PostgreSQL
Is this bug present after an update or on a fresh install?
Fresh Nextcloud Server install
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
(OIDC login.)
Configuration report
{
"memcache.distributed": "\\OC\\Memcache\\Redis",
"memcache.locking": "\\OC\\Memcache\\Redis",
"redis": {
"host": "tcp://redis-proxy",
"password": "***REMOVED SENSITIVE VALUE***",
"port": 6379
}
}
List of activated Apps
Not relevant to the report; the stack trace shows the Redis calls coming from core and from the webhook_listeners, workflowengine and notifications apps at boot.
Nextcloud Signing status
Not relevant to the report.
Nextcloud Logs
{"level":4,"method":"GET","url":"/login","message":"{\"Exception\":\"RedisException\",\"Message\":\"Connection lost\", ... \"file\":\"/var/www/html/lib/private/RedisFactory.php\",\"line\":104,\"function\":\"pconnect\", ... \"args\":[\"tcp://redis-proxy\",6379,0,null,0,0]"}
{"level":4,"method":"GET","url":"/login","message":"{\"Exception\":\"RedisException\",\"Message\":\"NOAUTH Authentication required.\", ... \"file\":\"/var/www/html/lib/private/Memcache/Redis.php\",\"line\":63,\"function\":\"get\"}"}
{"level":3,"method":"GET","url":"/login","message":"{\"Exception\":\"RedisException\",\"Message\":\"NOAUTH Authentication required.\", ... Notification/Manager.php ... isFairUseOfFreePushService"}
Additional info
Workaround on our side: the same patch to RedisFactory (setOption(\Redis::OPT_TCP_KEEPALIVE, true) after connect/pconnect, behind a config key) plus tcp_keepalive_time below the idle timeout. Setting redis.persistent to false also removes the failure, at the cost of one connection and AUTH per request. I can open a PR for the config key if there is interest.
- Langage dominant
- PHP
- Étoiles
- 37.6k
- Forks
- 5.4k
- Merge moyen
- 1 j 13 h
- PR mergées (30 j)
- 623
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de nextcloud/server
-
[Bug]: Axios Update NeededOuverte0. Needs triage 35-feedback bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
34-feedback
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: GET /js/../<anything> returns 500 (NotPermittedException from JsController::getJs) instead of 404Peut-être pris @lazerg l’a pris il y a 7 jours. Ouverte35-feedback
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: Dashboard widgets registered via OCA.Dashboard.register() sometimes never mount (spinner forever) – Vue 3 non-deep `callbacks` watcher racePeut-être pris @lazerg l’a pris il y a 7 jours. Ouverte35-feedback
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de nextcloud/server
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
sonata-project/SonataAdminBundle#8426 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
erkamyaman/rust-anything#942 ·
Les mainteneurs répondent en général sous 1 jour
-
CPU core labels missing for Low-Power E-cores on hybrid Intel CPUs (Arrow Lake-H) — get_intel_core_types() ignores /sys/devices/cpu_lowpowerPeut-être pris @dgongut l’a pris aujourd’hui. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
Les mainteneurs répondent en général sous 1 jour