[30.2] typesense_memory_resident_bytes reports stats.active instead of stats.resident

Aperta Adatta ai principianti
#3,070 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Il bug si trova in src/system_metrics.cpp righe 49-59, dove il valore stats.resident viene letto ma stats.active viene serializzato in modo errato come typesense_memory_resident_bytes. Inizia esaminando quel file e la logica di raccolta delle metriche circostante. Verifica la correzione compilando Typesense, eseguendo lo script di riproduzione fornito e controllando che l'endpoint /metrics.json ora riporti il valore corretto della memoria residente. Assicurati che la modifica compili e che i test esistenti passino.

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

Descrizione

pre-triage

Bug Description

On Typesense 30.2, GET /metrics.json publishes jemalloc's stats.active as typesense_memory_resident_bytes, even though it separately reads stats.resident.

This reproduces with zero collections and zero documents on the official image. The runtime symptom is identical active/resident values; the 30.2 source assignment establishes why they are identical.

Reproduction Steps

Requirements: Docker, Bash, curl and jq. No Typesense client library, credentials or dataset are needed.

Complete standalone Docker/curl reproduction (GitHub blob) · captured raw responses and environment

curl -fL 'https://raw.githubusercontent.com/colophon-group/jobseek/ba2a4212efdfe8125e3ae33050de72b76afc9b4e/scripts/repro-typesense-resident-metric.sh' \
  -o repro-typesense-resident-metric.sh
bash repro-typesense-resident-metric.sh

The script starts a disposable server on a dynamically assigned loopback port, waits for health, verifies /debug reports 30.2 and /collections is empty, then requests /metrics.json three times. It retains the results and removes its own container on exit.

The relevant API call is:

curl -fsS -H 'X-TYPESENSE-API-KEY: repro-key' "$base/metrics.json" |
  jq '{typesense_memory_active_bytes, typesense_memory_resident_bytes,
       typesense_memory_allocated_bytes, typesense_memory_metadata_bytes}'

Here base is the disposable server's URL, determined by the script.

Expected vs Actual

Expected: typesense_memory_resident_bytes contains the successfully retrieved jemalloc stats.resident value.

Actual: it contains stats.active. Fresh measurements on 30.2:

Request active bytes reported resident bytes metadata bytes
1 32,698,368 32,698,368 10,013,632
2 33,005,568 33,005,568 10,045,504
3 33,320,960 33,320,960 10,077,632

The first response, projected to the relevant fields:

{
  "typesense_memory_active_bytes": "32698368",
  "typesense_memory_resident_bytes": "32698368",
  "typesense_memory_allocated_bytes": "31400368",
  "typesense_memory_metadata_bytes": "10013632"
}

Absolute byte counts can vary by machine and run. Equality alone would not identify the cause; the source reads stats.resident into resident on line 51, then serializes active for the resident field on line 59. The apparent assignment correction is:

- result["typesense_memory_resident_bytes"] = std::to_string(active);
+ result["typesense_memory_resident_bytes"] = std::to_string(resident);

A regression test should verify that the response maps to the resident allocator statistic, with successful statistics retrieval, rather than merely asserting that two live measurements differ.

Environment

  • Typesense: 30.2, the latest stable release when checked on 2026-09-23; /debug returned {"state":1,"version":"30.2"}.
  • Official image: typesense/typesense:30.2@sha256:610f2d34b1f93d00762869da2c67736775e5798d19a2c8b91b014b8a0cc1e110.
  • Server: Linux 6.8.0-64-generic, aarch64; Docker Engine 28.4.0, image architecture arm64.
  • Client: curl 8.4.0 on macOS, jq 1.8.1; no SDK.

Schema / Configuration

No schema or documents. The official image runs with --data-dir=/tmp --api-key=repro-key, otherwise default server configuration. The key is a public local reproduction value.

Additional Context

The jemalloc documentation distinguishes allocator resident memory from active allocation pages and from operating-system process RSS. This report asks for the allocator statistic already being read; it does not ask for equality with Linux RSS.

The incorrect mapping can mislead memory-capacity and before/after optimization measurements. It is a reporting defect, not evidence of a leak or the cause of an OOM.

Related discussions: #366, #1595. I did not find a dedicated report of this assignment when searching issues and PRs for the metric name and stats.resident.

Lingua principale
C++
Stelle
27.1k
Fork
1k
Merge medio
4g 4h
PR unite (30g)
15

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 typesense/typesense

Tutte le issue di typesense/typesense

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.