Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

findNewIds() chunking can return massive duplicate/already-known ID sets and cause memory exhaustion

Abierto
#13,699 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@kesselb ya está trabajando en esto.

Desde el 28/9/2026.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php, postgresql

Línea de trabajo

Comienza en MessageMapper::findNewIds() y sigue el endpoint de sincronización del buzón que se utiliza cuando hay una búsqueda filtrada activa. Reproduce el comportamiento con más de 1.000 IDs conocidas y verifica después que el conjunto devuelto no contenga IDs conocidas ni duplicadas, y que la sincronización ya no se acerque al agotamiento de la memoria.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

0. to triage bug
Steps to reproduce
  1. Use a mailbox with more than 1000 locally known messages. In our case the mailbox had ~41,000 known messages.
  2. Open the mailbox in Nextcloud Mail and perform a filtered search.
  3. Let the client call the mailbox sync endpoint while the filter is active.
  4. Instrument MessageMapper::findNewIds() and compare the number of known IDs with the returned new IDs.

In our production case:

knownIds = 40810

but findNewIds() returned approximately:

newIds = 820000

In another request the filtered result reached approximately 982697 IDs.

The issue is caused by chunking the known ID list into groups of 1000 while NOT IN (:ids) only excludes the current chunk.

Expected behavior

findNewIds() should return only IDs that are not present in the complete known-ID set.

Each message ID should be returned at most once, regardless of how the known IDs are chunked internally.

Actual behavior

When the known ID list contains more than 1000 IDs, each SQL query excludes only the current 1000-ID chunk.

Known IDs belonging to the other chunks can therefore be returned again and again.

The results of all chunks are then concatenated, producing a very large result set.

In our case:

knownIds = 40810
newIds = ~820000

This caused the mailbox sync request to approach the 1 GB PHP memory limit and eventually fail with memory exhaustion.

We tested the following workaround successfully:

$knownIds = array_fill_keys($ids, true);
$results = [];

foreach (array_chunk($ids, 1000) as $chunk) {
    $select->setParameter('ids', $chunk, IQueryBuilder::PARAM_INT_ARRAY);

    foreach ($this->findIds($select) as $id) {
        if (!isset($knownIds[$id])) {
            $results[$id] = $id;
        }
    }
}

return array_values($results);
Mail app version

5.12.0

Nextcloud version

34.0.2

Mailserver or service

IMAP + Gmail

Operating system

Debian GNU/Linux 13 (trixie)

PHP engine version

Other

Nextcloud memory caching

memcache.local: APCu memcache.distributed: Redis memcache.locking: Redis

Web server

Apache (supported)

Database

PostgreSQL

Additional info

PHP: 8.5.10
Web server: Apache 2.4.68
OS: Debian GNU/Linux 13 (trixie)

Nextcloud memory caching:

  • memcache.local: \OC\Memcache\APCu
  • memcache.distributed: \OC\Memcache\Redis
  • memcache.locking: \OC\Memcache\Redis

PHP memory_limit: 1024M

The issue was reproduced on a mailbox with approximately 41,000 locally known messages.

Lenguaje dominante
JavaScript
Estrellas
1k
Forks
369
Merge medio
1 d 18 h
PR fusionados (30 d)
118

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nextcloud/mail

Todos los issues de nextcloud/mail

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.