[Bug]: A single multi-byte character in a LIKE literal crashes the whole QueryNode (NGRAM index)
Is there an existing issue for this?
- I have searched the existing issues
Environment
- Milvus version: 2.6.x
- Deployment mode(standalone or cluster): cluster
- SDK version(e.g. pymilvus v2.0.0rc2): pymilvus 2.6Current Behavior
A LIKE predicate whose literal (or any wildcard-free part of it, after wildcard splitting) is a single multi-byte UTF-8 character — e.g. ) (U+FF09) or 订 — aborts the whole QueryNode process. All four pattern shapes are affected; the plan parser (optimizeLikePattern) maps each to a match operator and every one funnels into the same ngram code path:
- InnerMatch:
title like '%)%'— literal")"(1 char / 3 bytes) - PrefixMatch:
title like '订%'— literal"订" - PostfixMatch:
title like '%)'— literal")" - Match:
title like '%abc%)%'— wildcard-split part")"
Inside the QueryNode, the filter pins the field's NGRAM index for any of these operators (PhyUnaryRangeFilterExpr), calls ExecNgramMatch(), and the C++ guard — comparing bytes — lets the 3-byte literal through (3 >= min_gram=2). The call then crosses into the Rust tantivy binding, whose assert counts characters (1 < 2):
thread '<unnamed>' panicked at src/index_reader.rs:568:9:
literal length should be larger or equal to min_gram. literal: 订, min_gram: 2
panic in a function that cannot unwind
13: tantivy_ngram_match_query
14: milvus::tantivy::TantivyIndexWrapper::ngram_match_query
15: milvus::index::NgramInvertedIndex::ExecuteQueryWithPredicate<std::string_view>
16: milvus::index::NgramInvertedIndex::ExecuteQuery
17: milvus::exec::PhyUnaryRangeFilterExpr::ExecNgramMatch
18..23: ExprSet::Eval -> PhyFilterBitsNode -> Driver (exec engine)
thread caused non-unwinding panic. aborting.(captured on official v2.6.18, cluster mode; frames 0–12 are Rust panic machinery)
Because tantivy_ngram_match_query is an extern "C" FFI function, the panic cannot unwind — Rust aborts the process. This is not a query error: the whole QueryNode dies, taking with it
- every in-flight query/search on that node — concurrent RPCs fail with connection errors, none of them related to the trigger;
- the trigger query itself, which never returns a meaningful error to its caller.
What the client sees is misleading infrastructure noise that points nowhere near the offending query:
MilvusException: code=503, message=fail to Query on QueryNode 2:
channel distribution is not serviceable: channel not available[channel=by-dev-rootcoord-dml_0_...v0]Crash loop. With a restart policy the pod returns after ~30 s (re-registration + segment reload, including the NGRAM index). Any client retry — SDK retry logic, a user refreshing, application error handling — executes the same LIKE and kills the node again. Empirically (official v2.6.18, docker compose): the container's RestartCount grew by exactly one per retry (17→23 in one session; 8/8 attempts on a fresh environment). With a single replica the shard stays unavailable for as long as anyone keeps retrying.
Expected Behavior
The query result meets expectations.
Steps To Reproduce
1. Build milvus2.6.18 standalone service using docker-compose.yaml.(The file is pasted at the back)
2. Use py scripts to create and query collection with 'like' operation.(The file is pasted at the back)
3. Reproduce that querynode crash and query return 'code=503, message=fail to Query on QueryNode 4982: channel distribution is not serviceable: channel not available'.Milvus Log
QueryNode Logs:
thread '<unnamed>' panicked at src/index_reader.rs:568:9:
literal length should be larger or equal to min_gram. literal: ?, min_gram: 2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at library/core/src/panicking.rs:225:5:
panic in a function that cannot unwind
stack backtrace:
0: 0x7f9684441372 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf435e8e9347709a8
1: 0x7f968448fd33 - core::fmt::write::h0a51fad3804c5e7c
2: 0x7f9684435933 - std::io::Write::write_fmt::h9759e4151bf4a45e
3: 0x7f96844411c2 - std::sys::backtrace::BacktraceLock::print::h1ec5ce5bb8ee285e
4: 0x7f9684444d9c - std::panicking::default_hook::{{closure}}::h5ffefe997a3c75e4
5: 0x7f9684444b9f - std::panicking::default_hook::h820c77ba0601d6bb
6: 0x7f96844457a2 - std::panicking::rust_panic_with_hook::h8b29cbe181d50030
7: 0x7f9684445526 - std::panicking::begin_panic_handler::{{closure}}::h9f5b6f6dc6fde83e
8: 0x7f9684441879 - std::sys::backtrace::__rust_end_short_backtrace::hd7b0c344383b0b61
9: 0x7f96844451ed - __rustc[5224e6b81cd82a8f]::rust_begin_unwind
10: 0x7f968255e66d - core::panicking::panic_nounwind_fmt::hdcc420bb84b07b49
11: 0x7f968255e702 - core::panicking::panic_nounwind::h681d69c581350003
12: 0x7f968255e8c2 - core::panicking::panic_cannot_unwind::h4320389209385803
13: 0x7f968355bbfc - tantivy_ngram_match_query
14: 0x7f9682a4db7b - _ZN6milvus7tantivy19TantivyIndexWrapper17ngram_match_queryERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmmPv.isra.0
15: 0x7f9682a4fe58 - _ZN6milvus5index18NgramInvertedIndex25ExecuteQueryWithPredicateISt17basic_string_viewIcSt11char_traitsIcEERZNS1_12ExecuteQueryERKNSt7__cxx1112basic_stringIcS5_SaIcEEENS_5proto4plan6OpTypeEPNS_4exec11SegmentExprEEUlRKS6_E0_EESt8optionalINS_6bitset6BitsetINSO_6detail33VectorizedElementWiseBitsetPolicyImNSQ_17VectorizedDynamicEEEN5folly8fbvectorIhSaIhEEELb1EEEESC_SI_OT0_b
16: 0x7f9682a56e13 - _ZN6milvus5index18NgramInvertedIndex12ExecuteQueryERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_5proto4plan6OpTypeEPNS_4exec11SegmentExprE
17: 0x7f968334d3e5 - _ZN6milvus4exec23PhyUnaryRangeFilterExpr14ExecNgramMatchEv
18: 0x7f96833b999f - _ZN6milvus4exec23PhyUnaryRangeFilterExpr20ExecRangeVisitorImplISt17basic_string_viewIcSt11char_traitsIcEEEESt10shared_ptrINS_10BaseVectorEERNS0_7EvalCtxE
19: 0x7f968334edb8 - _ZN6milvus4exec23PhyUnaryRangeFilterExpr4EvalERNS0_7EvalCtxERSt10shared_ptrINS_10BaseVectorEE
20: 0x7f96831a7d10 - _ZN6milvus4exec21PhyConjunctFilterExpr4EvalERNS0_7EvalCtxERSt10shared_ptrINS_10BaseVectorEE
21: 0x7f96831a7d10 - _ZN6milvus4exec21PhyConjunctFilterExpr4EvalERNS0_7EvalCtxERSt10shared_ptrINS_10BaseVectorEE
22: 0x7f96831ba7ae - _ZN6milvus4exec7ExprSet4EvalEiibRNS0_7EvalCtxERSt6vectorISt10shared_ptrINS_10BaseVectorEESaIS7_EE
23: 0x7f96833d92db - _ZN6milvus4exec17PhyFilterBitsNode9GetOutputEv
24: 0x7f9682f07a23 - _ZN6milvus4exec6Driver11RunInternalERSt10shared_ptrIS1_ERS2_INS0_13BlockingStateEERS2_INS_9RowVectorEE
25: 0x7f9682f08477 - _ZN6milvus4exec6Driver4NextERSt10shared_ptrINS0_13BlockingStateEE
26: 0x7f9682f0e421 - _ZN6milvus4exec4Task4NextEPN5folly10SemiFutureINS2_4UnitEEE
27: 0x7f9682c27ab5 - _ZN6milvus5query19ExecPlanNodeVisitor11ExecuteTaskERNS_4plan12PlanFragmentESt10shared_ptrINS_4exec12QueryContextEEb
28: 0x7f9682c294ae - _ZN6milvus5query19ExecPlanNodeVisitor5visitERNS0_16RetrievePlanNodeE
29: 0x7f9682dc723c - _ZNK6milvus7segcore24SegmentInternalInterface8RetrieveEPNS_6tracer12TraceContextEPKNS_5query12RetrievePlanEmlbRKN5folly17CancellationTokenEim
30: 0x7f9682e71472 - _ZN5folly6detail8function14FunctionTraitsIFvRNS_7futures6detail8CoreBaseEONS_8Executor9KeepAliveIS7_EEPNS_17exception_wrapperEEE7callBigIZNS4_4CoreINS_4UnitEE11setCallbackIZNS4_10FutureBaseISH_E18thenImplementationIZNOS_6FutureISH_E7thenTryIRZN6milvus7futures6FutureI6CProtoE12asyncProduceIZ13AsyncRetrieveEUlNS_17CancellationTokenEE_JESt9enable_ifILb1EvEEEvS9_iOT_EUlS11_E0_EENSN_INS4_17tryCallableResultISH_S10_NSY_IX14is_invocable_vIS10_ONS_3TryISH_EEEEvE4typeEE10value_typeEEES11_EUlSA_S17_E_NS4_25tryExecutorCallableResultISH_S1D_vEEEENSY_IXntsrNT0_13ReturnsFutureE5valueENS1G_6ReturnEE4typeES11_S1G_NS4_18InlineContinuationEEUlSA_S17_E_EEvS11_OSt10shared_ptrINS_14RequestContextEES1L_EUlS6_SA_SC_E_EEvS6_SA_SC_RNS1_4DataE
31: 0x7f967dc09e80 - _ZN5folly6detail8function14FunctionTraitsIFvvEE9callSmallIZNOS_8Executor9KeepAliveIS6_E3addIZNS_7futures6detail8CoreBase10doCallbackEOS8_NSB_5StateEEUlSD_E0_EEvOT_EUlvE_EEvRNS1_4DataE
32: 0x7f967db29fb6 - _ZN5folly18ThreadPoolExecutor7runTaskERKSt10shared_ptrINS0_6ThreadEEONS0_4TaskE
33: 0x7f967daecfb5 - _ZN5folly21CPUThreadPoolExecutor9threadRunESt10shared_ptrINS_18ThreadPoolExecutor6ThreadEE
34: 0x7f967db2c58c - _ZN5folly6detail8function14FunctionTraitsIFvvEE9callSmallISt5_BindIFMNS_18ThreadPoolExecutorEFvSt10shared_ptrINS7_6ThreadEEEPS7_SA_EEEEvRNS1_4DataE
35: 0x7f9680816253 - <unknown>
36: 0x7f9680ae1ac3 - <unknown>
37: 0x7f9680b72a84 - clone
38: 0x0 - <unknown>
thread caused non-unwinding panic. aborting.Anything else?
repro_querynode_crash.py
#!/usr/bin/env python3
"""Cluster-adapted variant of repro_ngram_panic.py.
Milvus 2.6 proxy rejects schemas without a vector field
(internal/proxy/task.go:414), so a dummy FLOAT_VECTOR field `emb` is added.
It plays no role in the repro: the LIKE filter runs on `title`'s NGRAM index
inside the QueryNode either way.
Usage: python3 repro_ngram_panic.py [uri] [variant] [-u USER [-p [PASSWORD]] | -a TOKEN]
Auth (optional): -u root -p milvus, or -a root:milvus (JWT also works),
or export MILVUS_PASSWORD=... and pass only -u.
"""
import argparse
import getpass
import os
import time
from pymilvus import MilvusClient, DataType
_PROMPT = object() # sentinel: bare `-p` (no value) -> ask interactively
def parse_args():
parser = argparse.ArgumentParser(
description="Reproduce the Milvus NGRAM QueryNode panic "
"(literal length should be larger or equal to min_gram)")
parser.add_argument("uri", nargs="?", default="http://localhost:19530",
help="Milvus endpoint (default: %(default)s)")
parser.add_argument("variant", nargs="?", default="inner",
choices=["inner", "prefix", "postfix", "match"],
help="LIKE pattern used as trigger (default: %(default)s)")
auth = parser.add_mutually_exclusive_group()
auth.add_argument("-u", "--user", default=None,
help="username, for clusters with auth enabled")
auth.add_argument("-a", "--token",
help="auth token 'username:password' or JWT; overrides -u/-p")
parser.add_argument("-p", "--password", nargs="?", const=_PROMPT, default=None,
help="password; bare -p prompts for it, otherwise falls "
"back to $MILVUS_PASSWORD")
args = parser.parse_args()
if not args.token:
if args.password is _PROMPT:
args.password = getpass.getpass(f"Password for {args.user or args.uri}: ")
elif args.password is None:
args.password = os.environ.get("MILVUS_PASSWORD")
if args.user and args.password is None:
args.password = getpass.getpass(f"Password for {args.user}: ")
return args
ARGS = parse_args()
URI = ARGS.uri
VARIANT = ARGS.variant
COLL = "ngram_panic_repro"
# v2.6.19+ datacoord has minRowsToBuildIndex=1024: smaller segments get a
# "fake finished" index and the QN never loads one -> brute force -> no crash.
# Insert above the threshold so the NGRAM index is really built.
N = 1100
TRIGGERS = {
"inner": 'title like "%)%"',
"prefix": 'title like ")%"',
"postfix": 'title like "%)"',
"match": 'title like "%abc%)%"',
}
if ARGS.token:
client = MilvusClient(uri=URI, token=ARGS.token)
elif ARGS.user:
client = MilvusClient(uri=URI, user=ARGS.user, password=ARGS.password or "")
else:
client = MilvusClient(uri=URI)
client.drop_collection(COLL)
schema = client.create_schema(auto_id=True, enable_dynamic_field=False)
schema.add_field("id", DataType.INT64, is_primary=True)
schema.add_field("title", DataType.VARCHAR, max_length=256)
schema.add_field("emb", DataType.FLOAT_VECTOR, dim=2)
index_params = client.prepare_index_params()
index_params.add_index(
field_name="title",
index_type="NGRAM",
params={"min_gram": 2, "max_gram": 3},
)
# load requires an index on the vector field too; FLAT builds nothing
index_params.add_index(
field_name="emb",
index_type="FLAT",
metric_type="L2",
)
client.create_collection(COLL, schema=schema, index_params=index_params)
base_titles = ["订单(已取消)", "中文测试", "hello world"]
rows = [
{"title": base_titles[i % 3], "emb": [0.0, 0.0]} for i in range(N)
]
client.insert(COLL, rows)
client.flush(COLL)
idx = {}
for _ in range(60):
idx = client.describe_index(COLL, "title")
if idx.get("pending_index_rows", 1) == 0 and idx.get("indexed_rows", 0) >= N:
break
time.sleep(1)
print("index:", idx)
client.load_collection(COLL)
# The NGRAM index reaches the QueryNode only AFTER load_collection returns
# (segment refresh with indexes_to_load). Querying earlier hits the brute-force
# path and can FALSELY look "not reproduced". Let it settle first.
SETTLE = int(os.environ.get("REPRO_SETTLE_SECONDS", "45"))
print(f"settling {SETTLE}s for QN index load ...")
time.sleep(SETTLE)
print("control:", client.query(
COLL, filter='title like "%(已取消%"', output_fields=["title"]))
print(f"trigger ({VARIANT}):", TRIGGERS[VARIANT])
for attempt in range(8):
try:
res = client.query(COLL, filter=TRIGGERS[VARIANT], output_fields=["title"])
print(f"trigger result (attempt {attempt}):", len(res), "rows")
print("NOT reproduced: query succeeded.")
break
except Exception as e: # noqa: BLE001
# a crashing QN shows up as 503 channel-not-serviceable / conn errors;
# retry like a real client would -> this is the crash-loop scenario
print(f"attempt {attempt} failed: {str(e)[:100]}")
time.sleep(5)
else:
print("all attempts failed -> QueryNode likely crash-looping. Its log shows:\n"
' panicked at src/index_reader.rs:568:\n'
' literal length should be larger or equal to min_gram. '
'literal: ), min_gram: 2\n'
' thread caused non-unwinding panic. aborting.')
docker-compose.yml
services:
etcd:
container_name: ngram-etcd
image: quay.io/coreos/etcd:v3.5.18
environment:
- ETCD_AUTO_COMPACTION_MODE=revision
- ETCD_AUTO_COMPACTION_RETENTION=1000
- ETCD_QUOTA_BACKEND_BYTES=4294967296
- ETCD_SNAPSHOT_COUNT=50000
volumes:
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
command: etcd -advertise-client-urls=http://etcd:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
healthcheck:
test: ["CMD", "etcdctl", "endpoint", "health"]
interval: 30s
timeout: 20s
retries: 3
restart: always
minio:
container_name: ngram-minio
image: minio/minio:RELEASE.2023-03-20T20-16-18Z
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
ports:
- "9000:9000"
- "9001:9001"
volumes:
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
command: minio server /minio_data --console-address ":9001"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
restart: always
mixcoord:
container_name: milvus-mixcoord
image: milvusdb/milvus:v2.6.18
command: ["milvus", "run", "mixcoord"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MINIO_REGION: us-east-1
MQ_TYPE: woodpecker
depends_on:
- "etcd"
- "minio"
restart: always
datanode:
container_name: milvus-datanode
image: milvusdb/milvus:v2.6.18
command: ["milvus", "run", "datanode"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MINIO_REGION: us-east-1
MQ_TYPE: woodpecker
depends_on:
- "etcd"
- "minio"
- "mixcoord"
restart: always
streamingnode:
container_name: milvus-streamingnode
image: milvusdb/milvus:v2.6.18
command: ["milvus", "run", "streamingnode"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MINIO_REGION: us-east-1
MQ_TYPE: woodpecker
depends_on:
- "etcd"
- "minio"
- "mixcoord"
restart: always
querynode:
container_name: milvus-querynode
image: milvusdb/milvus:v2.6.18
command: ["milvus", "run", "querynode"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MINIO_REGION: us-east-1
MQ_TYPE: woodpecker
depends_on:
- "etcd"
- "minio"
- "mixcoord"
restart: always
proxy:
container_name: milvus-proxy
image: milvusdb/milvus:v2.6.18
command: ["milvus", "run", "proxy"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MINIO_REGION: us-east-1
MQ_TYPE: woodpecker
depends_on:
- "etcd"
- "minio"
- "mixcoord"
ports:
- "19530:19530"
- "9091:9091"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
interval: 30s
start_period: 90s
timeout: 20s
retries: 3
restart: always
networks:
default:
name: milvus-ngram-repro
Source: milvus-io/milvus