Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#13,699 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kesselb ci sta già lavorando.

Dal 28/9/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, postgresql
Ambito
backend, databases

Direzione di ricerca

Inizia da MessageMapper::findNewIds() e segui l’endpoint di sincronizzazione della mailbox utilizzato quando è attiva una ricerca filtrata. Riproduci il comportamento con più di 1.000 ID noti, quindi verifica che l’insieme restituito non contenga ID noti o duplicati e che la sincronizzazione non si avvicini più all’esaurimento della memoria.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
JavaScript
Stelle
1k
Fork
359
Merge medio
2g 1h
PR unite (30g)
98

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextcloud/mail

Tutte le issue di nextcloud/mail

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.