#3077·typesense

macOS (arm64): concurrent POST /collections + GET /collections permanently wedge the write path ("Stuck req_key", queued_writes never drains)

Author: Vasiliy-BondarenkoCreated Sep 24, 2026Updated Sep 29, 2026
Labelsbug

Summary

On the native macOS arm64 build (v29.0 and v30.2), a handful of clients that concurrently create collections and list collections (GET /collections) wedge the node within ~20 seconds:

  • all in-flight requests (writes and GET /collections) stop responding,
  • /health stops responding,
  • raft status freezes with queued_writes: N, applying: 0,
  • the batched indexer logs Stuck req_key: … for the stuck requests,
  • the node never recovers, even after all clients disconnect,
  • SIGTERM does not stop the process (it blocks in Batched indexer threadpool shutdown...); only kill -9 works.

The same script against the official Docker images (typesense/typesense:30.2, typesense/typesense:31.0.rc17-arm64) on the same machine does not reproduce.

Environment

  • Hardware: Apple M1 Pro (10 cores), 32 GB RAM
  • OS: macOS 26.3.1 (build 25D771280a), arm64
  • Typesense, native (reproduces):
    • v29.0 — Homebrew typesense/tap/[email protected], sha256 f1540b769b51ee056248fbed1744e3f55567d502100398c19102aad25690e5cb
    • v30.2 — Homebrew typesense/tap/[email protected], sha256 086d498fbf0afb45091f4e28b50e803a3633daac506388a5f71e5ed90407c91f
    • v30.2 — official darwin-arm64 tarball from dl.typesense.org: byte-identical to the Homebrew binary (same sha256)
  • Typesense, Docker (does not reproduce): typesense/typesense:30.2 and typesense/typesense:31.0.rc17-arm64, Docker 24.0.6 (linux/arm64 VM)
  • Single node, fresh empty data dir for every run

Steps to reproduce

  1. Minimal config (no tuning; the same result with thread-pool-size = 64, max-indexing-concurrency = 8, larger RocksDB write buffers):

    ini
    [server]
    api-address = 127.0.0.1
    api-port = 8109
    peering-port = 8114
    api-key = xyz
    data-dir = /path/to/data
    log-dir = /path/to/log
  2. Start the server on an empty data dir:

    bash
    typesense-server --config=/path/to/typesense.ini
  3. Run the script below (Python 3 stdlib only):

    bash
    python3 repro_macos_hang.py --port 8109 --api-key xyz --workers 20 --seconds 90

Each worker loops: POST /collections (a new uniquely named collection with a single string field) and then GET /collections.

repro_macos_hang.py
python
#!/usr/bin/env python3
"""Reproduce a Typesense write-path hang: concurrent collection creates + collection listing.

Each worker thread loops:
    POST /collections   (create a new, uniquely named collection)
    GET  /collections   (list all collections)

If any request stays unanswered for longer than --stuck-after seconds, the script
prints HANG with the in-flight requests and exits with code 2. Otherwise it prints OK.

Only the Python standard library is used.

Usage:
    python3 repro_macos_hang.py --port 8109 --api-key xyz --workers 20 --seconds 90
"""
import argparse
import http.client
import json
import os
import sys
import threading
import time
import uuid

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--host", default="localhost")
parser.add_argument("--port", type=int, default=8108)
parser.add_argument("--api-key", default="xyz")
parser.add_argument("--workers", type=int, default=20)
parser.add_argument("--seconds", type=int, default=90)
parser.add_argument("--stuck-after", type=float, default=20.0, help="seconds without a response to call it a hang")
parser.add_argument("--no-list", action="store_true", help="skip GET /collections (control run)")
args = parser.parse_args()

HEADERS = {"X-TYPESENSE-API-KEY": args.api_key, "Content-Type": "application/json"}
RUN_ID = uuid.uuid4().hex[:8]

deadline = time.time() + args.seconds
op_count = [0] * args.workers
in_flight = {}  # worker -> (start_time, start_unix_us, "METHOD path")
lock = threading.Lock()


def worker(w: int) -> None:
    conn = http.client.HTTPConnection(args.host, args.port, timeout=3600)

    def request(method: str, path: str, body: dict | None = None) -> None:
        with lock:
            in_flight[w] = (time.time(), int(time.time() * 1e6), f"{method} {path}")
        conn.request(method, path, body=json.dumps(body) if body is not None else None, headers=HEADERS)
        response = conn.getresponse()
        response.read()
        with lock:
            in_flight.pop(w, None)
        op_count[w] += 1

    n = 0
    while time.time() < deadline:
        n += 1
        name = f"repro_{RUN_ID}_w{w}_{n}"
        request("POST", "/collections", {"name": name, "fields": [{"name": "title", "type": "string"}]})
        if not args.no_list:
            request("GET", "/collections")


def safe_worker(w: int) -> None:
    try:
        worker(w)
    except Exception as exc:  # connection refused/reset etc. is a setup problem, not a hang
        print(f"ERROR worker {w}: {exc!r}")
        sys.stdout.flush()
        os._exit(1)


threads = [threading.Thread(target=safe_worker, args=(w,), daemon=True) for w in range(args.workers)]
started = time.time()
for t in threads:
    t.start()

while any(t.is_alive() for t in threads):
    time.sleep(1)
    now = time.time()
    with lock:
        stuck = {w: v for w, v in in_flight.items() if now - v[0] > args.stuck_after}
        snapshot = sorted(in_flight.items(), key=lambda item: item[1][0])
    if stuck:
        print(f"HANG workers={args.workers} after {now - started:.0f}s, completed requests={sum(op_count)}")
        for w, (t0, t_us, desc) in snapshot:
            print(f"  worker {w:2d}: sent at unix_us={t_us}, waiting {now - t0:.1f}s: {desc}")
        sys.stdout.flush()
        os._exit(2)

total = sum(op_count)
print(f"OK workers={args.workers} {args.seconds}s completed requests={total} ({total / args.seconds:.0f}/s)")

Expected behavior

All requests complete (as they do in Docker, at roughly 190 requests/s for the same script and machine).

Actual behavior

Within ~20 s, requests stop being answered and never complete:

HANG workers=20 after 20s, completed requests=21
  worker  0: sent at unix_us=1790261544239985, waiting 20.1s: POST /collections
  worker  1: sent at unix_us=1790261544240111, waiting 20.1s: POST /collections
  ...

curl localhost:8109/health times out. Nothing changes after the clients exit.

Results (90 s per run, fresh data dir each run)

Build 20 workers 5 workers 2–3 workers 20 workers, --no-list (no GET /collections)
macOS native v30.2 (Homebrew = official tarball) HANG 3/3 (after ~20 s) HANG 3/4 OK 6/6 OK (≈147k requests, 1.6k/s)
macOS native v29.0 (Homebrew) HANG 3/3 (after ~20 s) — — —
Docker typesense/typesense:30.2 OK 3/3 (~190 req/s) OK 1/1 — —
Docker typesense/typesense:31.0.rc17-arm64 OK* — — —

* 31.0.rc17 was tested with an earlier, equivalent version of this script (concurrent POST /collections + GET /collections with a larger schema, 20 clients): OK in 2/2 runs, plus OK in 3/3 runs of heavier workloads (collection re-creation + listing, alias rotation) that hang the native builds.

Log excerpts (native v30.2, the run shown above)

Raft status freezes with queued writes that are never applied:

raft_server.cpp:759] Term: 2, last_index: 21, committed: 21, known_applied: 21, applying: 0, pending_writes: 0, queued_writes: 4, inflight_searches: 0, local_sequence: 93

The batched indexer's GC sees the requests every minute; after ~5 minutes it reports them as stuck (keys are within ~10 ms of the client-side send times above):

batched_indexer.cpp:432] Running GC for aborted requests, req map size: 4, reference_q.size: 0
batched_indexer.cpp:441] Stuck req_key: 1790261544249850
batched_indexer.cpp:441] Stuck req_key: 1790261544249983
batched_indexer.cpp:441] Stuck req_key: 1790261544250020
batched_indexer.cpp:441] Stuck req_key: 1790261544250059

SIGTERM gets as far as the batch indexer shutdown and blocks there (process still alive 30 s later; only kill -9 stops it):

raft_server.cpp:1054] Waiting for in-flight writes to finish...
typesense_server_utils.cpp:700] Shutting down batch indexer...
typesense_server_utils.cpp:703] Waiting for batch indexing thread to be done...
batched_indexer.cpp:486] Notifying batch indexer threads about shutdown...
batched_indexer.cpp:492] Notifying reference sequence thread about shutdown...
batched_indexer.cpp:496] Batched indexer threadpool shutdown...

No error-level lines are logged apart from the usual single-node startup messages (Node not ready yet (known_applied_index is 0), Peer refresh failed, error: Doing another configuration change).

Observations

  • The trigger is GET /collections combined with concurrent collection creation. Without GET /collections (--no-list), 20 workers run for 90 s without a problem. Creating and deleting collections concurrently (no listing) for 120 s is also fine.
  • GET /aliases in place of GET /collections does not trigger it (≈1k requests/s for 90 s, 2/2 runs OK).
  • GET /collections?exclude_fields=fields still hangs.
  • Documents are not needed (collections stay empty), and neither are aliases or deletes.
  • thread-pool-size = 64 does not help; neither do the default config or a tuned config (max-indexing-concurrency = 8, db-write-buffer-size = 268435456, db-max-write-buffer-number = 4).
  • Concurrency threshold: 2–3 clients never hung (6 runs), 5 clients hung in 3 of 4 runs, and 10–20 clients hang almost every time.
  • The node never recovers on its own, even after all clients disconnect (we waited more than 5 minutes).
  • We first hit this with a test suite running in parallel (about 20 workers that recreate collections per test, occasionally listing collections).

Possibly related

  • #3032, "Batched indexer intermittently wedges under sustained import pressure": same Stuck req_key / queued_writes plateau / applying: 0 symptoms, but there the trigger is sustained bulk document imports on a large collection (there the stuck request clears when the client disconnects). Here the trigger is collection-schema operations plus GET /collections, with empty collections. It is macOS-only, and disconnecting does not help. It may share a root cause in the batched indexer.