v1.53.1: exiting tokio-rt-worker spins forever in mimalloc _mi_thread_done, then tokio worker threads leak until OOM
Describe the bug
On v1.53.1 a tokio-rt-worker thread that is exiting gets stuck forever in mimalloc's thread-local heap teardown (_mi_thread_done → mi_heap_collect_ex → _mi_page_free_collect), pinning one core at 100%. From that moment on, new tokio-rt-worker threads are created at 2 to 3 per minute and never released. After ~36 h the process has ~6000 threads and ~14 GiB RSS for a 2.3 GB database, and the host starts swapping. Indexing, embedder requests, search and hybrid search keep working normally the whole time, so nothing alerts except CPU and memory.
It has happened twice in 12 days on the same host, 6 and 3.5 days after a clean start. The same process lineage also had one kernel-reported general protection fault in a tokio-rt-worker on Sep 11, which is probably the same corrupted heap state taking a crash exit instead of a spin. This looks closely related to #6572 (Intel hosts, v1.53.1, mimalloc suspected), but with a live backtrace that points at a specific mimalloc function, and a leak/spin symptom rather than a SIGSEGV, so I am filing it separately as requested by the template and linking the two.
To Reproduce
No standalone reproduction. It appears under steady production load:
- One index, ~1700 documents, 2.3 GB on disk, three
openAiembedders (text-embedding-3-small) with document templates. - Constant write traffic from meilisearch-go v0.36.3: 130 to 180 tasks/min of small
documentAdditionOrUpdate(1 to 20 docs) plus occasional single-documentdocumentDeletion, with the client pollingGET /tasks/:uidafter each write. - Plain single-index
POST /indexes/:uid/searchtraffic. No multi-search, no federation. - Wait a few days. Watch
ls /proc/$(pidof meilisearch)/task | wc -lclimb from ~50.
Thread creation histogram from /proc/<pid>/task/*/stat start times, first occurrence:
Sep 11: 48 (baseline: 40 embedding-request threads + runtime)
Sep 17: 337 (onset 19:13 UTC)
Sep 18: 4300
Sep 19: 1777 (until 07:00 UTC, then restarted)Second occurrence, onset Sep 22 19:27 UTC, same rate, 5914 threads when inspected on Sep 24.
At onset there is nothing in the log: no WARN/ERROR, no settings task, no failed embedder request, no non-2xx apart from the client's routine 404 on GET /documents/:id, no slow request.
Expected behavior
Exiting worker threads finish exiting. Thread count and RSS stay flat under constant load.
Backtraces
Captured with gdb attached to the live process during the second occurrence (35 h into the spin). Symbols are from the release binary, no debuginfo.
The spinning thread. It is not in Meilisearch or tokio code, it is a thread that has already run its exit path into libc TSD destruction:
===== TID 1364980 (tokio-rt-worker), 100% CPU, state R, 125,876 s CPU time =====
#0 0x000055a6e4cd7a76 in _mi_page_free_collect ()
#1 0x000055a6e4cdd01c in mi_heap_collect_ex ()
#2 0x000055a6e4cde742 in _mi_thread_done ()
#3 0x00007f4e618ef050 in __nptl_deallocate_tsd () from /lib64/libc.so.6
#4 0x00007f4e618f1b3b in start_thread () from /lib64/libc.so.6
#5 0x00007f4e619648cc in clone3 () from /lib64/libc.so.6A representative leaked thread (all ~5850 of them look like this, parked in futex_wait right after start):
===== TID 1462371 (tokio-rt-worker), parked =====
#0 0x00007f4e6196267d in syscall () from /lib64/libc.so.6
#1 0x000055a6e6da536e in parking_lot::condvar::Condvar::wait_until_internal ()
#2 0x000055a6e6d7b382 in std::sys::backtrace::__rust_begin_short_backtrace ()
#3 0x000055a6e6d7c4dd in core::ops::function::FnOnce::call_once{{vtable.shim}} ()
#4 0x000055a6e6dca0df in std::sys::thread::unix::Thread::new::thread_start ()
#5 0x00007f4e618f1cbd in start_thread () from /lib64/libc.so.6
#6 0x00007f4e619648cc in clone3 () from /lib64/libc.so.60x00007f4e61964cf2 in epoll_wait () from target:/lib64/libc.so.6
===== TID 1364980 (tokio-rt-worker) =====
#0 0x000055a6e4cd7a76 in _mi_page_free_collect ()
#1 0x000055a6e4cdd01c in mi_heap_collect_ex ()
#2 0x000055a6e4cde742 in _mi_thread_done ()
#3 0x00007f4e618ef050 in __nptl_deallocate_tsd () from target:/lib64/libc.so.6
#4 0x00007f4e618f1b3b in start_thread () from target:/lib64/libc.so.6
#5 0x00007f4e619648cc in clone3 () from target:/lib64/libc.so.6
===== TID 1462371 (tokio-rt-worker) =====
#0 0x00007f4e6196267d in syscall () from target:/lib64/libc.so.6
#1 0x000055a6e6da536e in parking_lot::condvar::Condvar::wait_until_internal ()
#2 0x000055a6e6d7b382 in std::sys::backtrace::__rust_begin_short_backtrace ()
#3 0x000055a6e6d7c4dd in core::ops::function::FnOnce::call_once{{vtable.shim}} ()
#4 0x000055a6e6dca0df in std::sys::thread::unix::Thread::new::thread_start ()
#5 0x00007f4e618f1cbd in start_thread () from target:/lib64/libc.so.6
#6 0x00007f4e619648cc in clone3 () from target:/lib64/libc.so.6
[Inferior 1 (process 1104392) detached]Command used: gdb -batch -p <pid> -x bt.py, where the script switches to the two TIDs and runs bt 40.
Earlier kernel trap on the previous process of the same install (Sep 11, no core captured at the time):
traps: tokio-rt-worker[735305] general protection fault ip:557e9129454f sp:7cf8425f3270 error:0 in meilisearch[52c554f,557e9118a000+224b000]Fault offset relative to the mapping base: 0x10A54F.
Other observations
/proc/<pid>/statusat 36 h:Threads: 6465,VmRSS: 13.8 GiB,RssAnon: 13.5 GiB,RssFile: 335 MiB,VmSwap: 1.0 GiB. 32 open fds, 3 established sockets. So no fd or socket leak, the memory is thread stacks and per-thread heaps.- Spinning thread: 3.3 M involuntary context switches, ~40 voluntary. A pure busy loop, never blocks.
systemctl restartfully clears it: ~50 threads, 130 MiB RSS.- The two onsets were at 19:13 UTC and 19:27 UTC on different days. Possibly coincidence, no timer or cron on the host fires then, but noting it.
- The embedder path is healthy during the leak: new documents get vectors,
embedderRequests.failedis 0 in every batch, hybrid search answers in ~4 ms.
Meilisearch version:
v1.53.1, official meilisearch-linux-amd64 release binary, commit 577f7af, mapping size 0x224b000. Run directly under systemd, not in Docker. Started from /etc/meilisearch.toml with max_indexing_threads = 2, max_indexing_memory = "10 GiB", experimental_enable_metrics = true, everything else default.
Additional context
- VMware VM, 2 vCPU Intel Xeon Gold 6544Y, 15 GiB RAM, 2 GiB swap, RHEL-family 10 (glibc with
clone3), kernel 6.x. - The reproduction is reliable enough here (twice in 12 days) that I can run a prototype build with a different allocator, or mimalloc with debug/secure options, and report back. Core capture is being enabled for the next GPF.
Source: meilisearch/meilisearch