tantivy icon indicating copy to clipboard operation
tantivy copied to clipboard

segment_postings assertion failed: self.doc() <= target

Open Dig-Doug opened this issue 8 months ago • 2 comments

Describe the bug

  • What did you do?

I am trying to call query.explain

  • What happened?
thread 'main' panicked at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/postings/segment_postings.rs:173:9:
assertion failed: self.doc() <= target
stack backtrace:
   0:     0x55cafde5aac2 - std::backtrace_rs::backtrace::libunwind::trace::hc20b48b31ee52608
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x55cafde5aac2 - std::backtrace_rs::backtrace::trace_unsynchronized::h5d207cd20f193d88
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x55cafde5aac2 - std::sys::backtrace::_print_fmt::h46402c32145e026c
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:66:9
   3:     0x55cafde5aac2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc04c8f544ab24d66
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:39:26
   4:     0x55cafde8a3f3 - core::fmt::rt::Argument::fmt::h2bcd587ea50ac9a4
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/fmt/rt.rs:184:76
   5:     0x55cafde8a3f3 - core::fmt::write::hfe57b7174b7d8eab
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/fmt/mod.rs:1481:21
   6:     0x55cafde563e3 - std::io::default_write_fmt::h20c7e2d50577e95e
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/io/mod.rs:639:11
   7:     0x55cafde563e3 - std::io::Write::write_fmt::h154385efa8565236
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/io/mod.rs:1914:13
   8:     0x55cafde5a912 - std::sys::backtrace::BacktraceLock::print::h0c8f24e22f5873a8
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:42:9
   9:     0x55cafde5b972 - std::panicking::default_hook::{{closure}}::hd07d57e6a602c8e4
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:300:22
  10:     0x55cafde5b775 - std::panicking::default_hook::h63d12f7d95bd91ed
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:327:9
  11:     0x55cafde5c312 - std::panicking::rust_panic_with_hook::h33b18b24045abff4
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:833:13
  12:     0x55cafde5c086 - std::panicking::begin_panic_handler::{{closure}}::hf8313cc2fd0126bc
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:699:13
  13:     0x55cafde5afc9 - std::sys::backtrace::__rust_end_short_backtrace::h57fe07c8aea5c98a
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:168:18
  14:     0x55cafde5bd4d - __rustc[95feac21a9532783]::rust_begin_unwind
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
  15:     0x55caf9453250 - core::panicking::panic_fmt::hd54fb667be51beea
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
  16:     0x55caf94532dc - core::panicking::panic::h48a7e1f3665210c6
                               at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:145:5
  17:     0x55cafaef260f - <tantivy::postings::segment_postings::SegmentPostings as tantivy::docset::DocSet>::seek::h407799e3e3c791ad
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/postings/segment_postings.rs:173:9
  18:     0x55cafae7920a - <tantivy::query::term_query::term_scorer::TermScorer as tantivy::docset::DocSet>::seek::ha893f717bb7f7b91
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/term_query/term_scorer.rs:106:9
  19:     0x55cafaf33e3b - <alloc::boxed::Box<TDocSet> as tantivy::docset::DocSet>::seek::hbc07717bb76ce4f0
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/docset.rs:154:9
  20:     0x55cafb02c353 - <tantivy::query::const_score_query::ConstScorer<TDocSet> as tantivy::docset::DocSet>::seek::hfc8ffe0296957279
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/const_score_query.rs:119:9
  21:     0x55cafaf33e3b - <alloc::boxed::Box<TDocSet> as tantivy::docset::DocSet>::seek::hbc07717bb76ce4f0
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/docset.rs:154:9
  22:     0x55cafb02be9f - <tantivy::query::const_score_query::ConstWeight as tantivy::query::weight::Weight>::explain::hb1b71ff7f6227103
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/const_score_query.rs:73:12
  23:     0x55cafb02ab9f - <tantivy::query::boolean_query::boolean_weight::BooleanWeight<TScoreCombiner> as tantivy::query::weight::Weight>::explain::h69c2ca6f3113da39
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/boolean_query/boolean_weight.rs:286:48
  24:     0x55cafb02ab9f - <tantivy::query::boolean_query::boolean_weight::BooleanWeight<TScoreCombiner> as tantivy::query::weight::Weight>::explain::h69c2ca6f3113da39
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/boolean_query/boolean_weight.rs:286:48
  25:     0x55cafaeb2dcf - tantivy::query::query::Query::explain::h5b13b18331b23e21
                               at /home/doug/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tantivy-0.24.1/src/query/query.rs:141:9

  • What was expected?

I expect this assertion not to fail.

Which version of tantivy are you using?

tantivy = "0.24.1"

To Reproduce

  • Build index with a bunch of documents and fields
  • Build boolean query with sub-queries
  • Run search (succeeds)
  • Try to explain query, panics in debug build

If your bug is deterministic, can you give a minimal reproducing code?

The bug is deterministic. I cannot share the full project but I'm trying to narrow down a small example. If you have any suggestions on what the key components might be, let me know.

Dig-Doug avatar Jun 05 '25 11:06 Dig-Doug

I think that debug_assert is too strict

fn seek(&mut self, target: DocId) -> DocId {
    debug_assert!(self.doc() <= target);
    if self.doc() >= target {
        return self.doc();
    }
   ...
}

Do you have something to reproduce? Did you try to run in release mode?

PSeitz avatar Jun 25 '25 13:06 PSeitz

In release mode, the code seems to work fine.

I exported my index data and created a script to repro in here.

Steps

cd /tmp 
git clone https://github.com/Dig-Doug/tantivy.git                                                                                                                                     
cd tantivy 
git checkout issue-2645 
RUST_BACKTRACE=full cargo run --example bug_reproduction 

Error

thread 'main' panicked at src/query/phrase_query/phrase_scorer.rs:523:9:
assertion failed: target >= self.doc()
stack backtrace:
   0:     0x5897756e53e2 - std::backtrace_rs::backtrace::libunwind::trace::h74680e970b6e0712
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x5897756e53e2 - std::backtrace_rs::backtrace::trace_unsynchronized::ha3bf590e3565a312
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x5897756e53e2 - std::sys::backtrace::_print_fmt::hcf16024cbdd6c458
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:66:9
   3:     0x5897756e53e2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h46a716bba2450163
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:39:26
   4:     0x589775708523 - core::fmt::rt::Argument::fmt::ha695e732309707b7
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/rt.rs:181:76
   5:     0x589775708523 - core::fmt::write::h275e5980d7008551
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/mod.rs:1446:25
   6:     0x5897756e2c73 - std::io::default_write_fmt::hdc4119be3eb77042
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:639:11
   7:     0x5897756e2c73 - std::io::Write::write_fmt::h561a66a0340b6995
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:1914:13
   8:     0x5897756e5232 - std::sys::backtrace::BacktraceLock::print::hafb9d5969adc39a0
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:42:9
   9:     0x5897756e6822 - std::panicking::default_hook::{{closure}}::hae2e97a5c4b2b777
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:300:22
  10:     0x5897756e6625 - std::panicking::default_hook::h3db1b505cfc4eb79
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:327:9
  11:     0x5897756e71c2 - std::panicking::rust_panic_with_hook::h409da73ddef13937
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:833:13
  12:     0x5897756e6f36 - std::panicking::begin_panic_handler::{{closure}}::h159b61b27f96a9c2
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:699:13
  13:     0x5897756e58d9 - std::sys::backtrace::__rust_end_short_backtrace::h5b56844d75e766fc
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:168:18
  14:     0x5897756e6bfd - __rustc[4794b31dd7191200]::rust_begin_unwind
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
  15:     0x589775141100 - core::panicking::panic_fmt::hc8737e8cca20a7c8
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
  16:     0x58977514118c - core::panicking::panic::h4a11c031239f36a8
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:145:5
  17:     0x5897751c470d - <tantivy::query::phrase_query::phrase_scorer::PhraseScorer<TPostings> as tantivy::docset::DocSet>::seek::h9ccef10c6f09b838
                               at /tmp/tantivy/src/query/phrase_query/phrase_scorer.rs:523:9
  18:     0x5897752f8cee - <tantivy::query::phrase_query::phrase_weight::PhraseWeight as tantivy::query::weight::Weight>::explain::h9f1d89436f0c1147
                               at /tmp/tantivy/src/query/phrase_query/phrase_weight.rs:91:12
  19:     0x5897752d8caf - <tantivy::query::boolean_query::boolean_weight::BooleanWeight<TScoreCombiner> as tantivy::query::weight::Weight>::explain::ha8b817eed8803288
                               at /tmp/tantivy/src/query/boolean_query/boolean_weight.rs:286:48
  20:     0x58977520b5ef - tantivy::query::query::Query::explain::hc79f613b9bba8cb0
                               at /tmp/tantivy/src/query/query.rs:141:9
  21:     0x58977515c78a - bug_reproduction::main::h56ab7fbcf1b30ab0
                               at /tmp/tantivy/examples/bug_reproduction.rs:40:28
  22:     0x589775159142 - core::ops::function::FnOnce::call_once::h72dfba8e305b5600
                               at /home/doug/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  23:     0x58977515bd65 - std::sys::backtrace::__rust_begin_short_backtrace::hb6cc36d9c1b154cb
                               at /home/doug/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
  24:     0x589775148814 - std::rt::lang_start::{{closure}}::h1adf434b51453718
                               at /home/doug/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:199:18
  25:     0x5897756dcf74 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb4b7cf0559a1a53b
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:284:13
  26:     0x5897756dcf74 - std::panicking::try::do_call::h8e6004e979ada7de
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
  27:     0x5897756dcf74 - std::panicking::try::hc44a0c902e55fa8c
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  28:     0x5897756dcf74 - std::panic::catch_unwind::h6a5f1ccd4faaed9e
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  29:     0x5897756dcf74 - std::rt::lang_start_internal::{{closure}}::h40fd26f9e7cfe6a7
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:168:24
  30:     0x5897756dcf74 - std::panicking::try::do_call::h047dd894cf3f6fd1
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
  31:     0x5897756dcf74 - std::panicking::try::h921841e1eaed56ce
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  32:     0x5897756dcf74 - std::panic::catch_unwind::h108064a50ee785ec
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  33:     0x5897756dcf74 - std::rt::lang_start_internal::ha8ef919ae4984948
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:164:5
  34:     0x5897751487f7 - std::rt::lang_start::hb1fa842122894dbf
                               at /home/doug/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:198:5
  35:     0x58977515caae - main
  36:     0x79ff3d22a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  37:     0x79ff3d22a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  38:     0x589775141c65 - _start
  39:                0x0 - <unknown>

Dig-Doug avatar Jun 29 '25 11:06 Dig-Doug