Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread 'Worker' panicked at 'invalid offset' #14839

Closed
lh123 opened this issue May 18, 2023 · 6 comments · Fixed by #17157 or #17554
Closed

Thread 'Worker' panicked at 'invalid offset' #14839

lh123 opened this issue May 18, 2023 · 6 comments · Fixed by #17157 or #17554
Labels
C-bug Category: bug I-panic

Comments

@lh123
Copy link
Contributor

lh123 commented May 18, 2023

rust-analyzer version: 0.0.0 (e4977e7 2023-05-18)

rustc version: rustc 1.69.0 (84c898d65 2023-04-16)

RA panic when invoke CallHierarchy on rust_analyzer::handlers::request::handle_completion

Panic context:
> 
version: 0.0.0 (e4977e74d 2023-05-18)
request: callHierarchy/outgoingCalls CallHierarchyOutgoingCallsParams {
    item: CallHierarchyItem {
        name: "completions",
        kind: Function,
        tags: None,
        detail: Some(
            "pub fn completions(db: &RootDatabase, config: &CompletionConfig, position: FilePosition, trigger_character: Option<char>) -> Option<Vec<CompletionItem>>",
        ),
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/lh/rust-src/rust-analyzer/crates/ide-completion/src/lib.rs",
            query: None,
            fragment: None,
        },
        range: Range {
            start: Position {
                line: 97,
                character: 0,
            },
            end: Position {
                line: 204,
                character: 1,
            },
        },
        selection_range: Range {
            start: Position {
                line: 147,
                character: 7,
            },
            end: Position {
                line: 147,
                character: 18,
            },
        },
        data: None,
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread 'Worker' panicked at 'invalid offset', lib/line-index/src/lib.rs:148:35
stack backtrace:
   0: rust_begin_unwind
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
   1: core::panicking::panic_fmt
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
   2: core::panicking::panic_display
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:147:5
   3: core::panicking::panic_str
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:131:5
   4: core::option::expect_failed
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/option.rs:2045:5
   5: core::option::Option<T>::expect
   6: line_index::LineIndex::line_col
   7: rust_analyzer::to_proto::position
   8: rust_analyzer::to_proto::range
   9: rust_analyzer::handlers::request::handle_call_hierarchy_outgoing::{{closure}}
  10: core::iter::adapters::map::map_fold::{{closure}}
  11: core::iter::traits::iterator::Iterator::fold
  12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  13: core::iter::traits::iterator::Iterator::for_each
  14: alloc::vec::Vec<T,A>::extend_trusted
  15: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
  16: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
  17: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  18: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
  19: core::iter::traits::iterator::Iterator::collect
  20: rust_analyzer::handlers::request::handle_call_hierarchy_outgoing
  21: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
  22: std::panicking::try::do_call
  23: __rust_try
  24: std::panicking::try
  25: std::panic::catch_unwind
  26: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}
  27: rust_analyzer::task_pool::TaskPool<T>::spawn::{{closure}}
  28: <F as threadpool::FnBox>::call_box
  29: threadpool::spawn_in_pool::{{closure}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@lh123 lh123 added the C-bug Category: bug label May 18, 2023
@lh123
Copy link
Contributor Author

lh123 commented May 18, 2023

let line_col = line_index.index.line_col(offset);

It seems that just ignoring this error can make RA work again

    let line_col = match line_index.index.try_line_col(offset) {
        Some(line_col) => line_col,
        None => return lsp_types::Position::new(0, 0),
    };

@lh123
Copy link
Contributor Author

lh123 commented Jun 2, 2023

Minimal repo:

Just invoke callHierarchy/outgoingCalls on take method

fn main() {
    let _a = Some(5).take();
    //               ^^^^   Invoke outgoing call hierarchy here!
}

image
image

version: 0.0.0 (0b4c09b1d 2023-06-01)
request: callHierarchy/outgoingCalls CallHierarchyOutgoingCallsParams {
    item: CallHierarchyItem {
        name: "take",
        kind: Function,
        tags: None,
        detail: Some(
            "pub const fn take(&mut self) -> Option<T>",
        ),
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/lh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs",
            query: None,
            fragment: None,
        },
        range: Range {
            start: Position {
                line: 1723,
                character: 4,
            },
            end: Position {
                line: 1744,
                character: 5,
            },
        },
        selection_range: Range {
            start: Position {
                line: 1741,
                character: 17,
            },
            end: Position {
                line: 1741,
                character: 21,
            },
        },
        data: None,
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread 'Worker' panicked at 'invalid offset', lib/line-index/src/lib.rs:148:35
stack backtrace:
   0: rust_begin_unwind
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
   1: core::panicking::panic_fmt
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
   2: core::panicking::panic_display
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:147:5
   3: core::panicking::panic_str
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:131:5
   4: core::option::expect_failed
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/option.rs:2045:5
   5: core::option::Option<T>::expect
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/option.rs:905:21
   6: line_index::LineIndex::line_col
             at /home/lh/rust-src/rust-analyzer/lib/line-index/src/lib.rs:148:9
   7: rust_analyzer::to_proto::position
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/to_proto.rs:31:20
   8: rust_analyzer::to_proto::range
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/to_proto.rs:42:17
   9: rust_analyzer::handlers::request::handle_call_hierarchy_incoming::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs:1422:27
  10: core::iter::adapters::map::map_fold::{{closure}}
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/iter/adapters/map.rs:84:28
  11: core::iter::traits::iterator::Iterator::fold
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/iter/traits/iterator.rs:2477:21
  12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/iter/adapters/map.rs:124:9
  13: core::iter::traits::iterator::Iterator::for_each
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/iter/traits/iterator.rs:852:9
  14: alloc::vec::Vec<T,A>::extend_trusted
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2856:17
  15: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/spec_extend.rs:26:9
  16: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/spec_from_iter_nested.rs:62:9
  17: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/in_place_collect.rs:167:20
  18: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2724:9
  19: core::iter::traits::iterator::Iterator::collect
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/iter/traits/iterator.rs:1891:9
  20: rust_analyzer::handlers::request::handle_call_hierarchy_outgoing
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs:1454:26
  21: rust_analyzer::dispatch::RequestDispatcher::on_with_thread_intent::{{closure}}::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/dispatch.rs:186:21
  22: std::panicking::try::do_call
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487:40
  23: std::panicking::try
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451:19
  24: std::panic::catch_unwind
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140:14
  25: rust_analyzer::dispatch::RequestDispatcher::on_with_thread_intent::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/dispatch.rs:184:30
  26: rust_analyzer::task_pool::TaskPool<T>::spawn::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/rust-analyzer/src/task_pool.rs:24:33
  27: stdx::thread::pool::Pool::spawn::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/stdx/src/thread/pool.rs:82:13
  28: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5
  29: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
  30: stdx::thread::pool::Pool::new::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/stdx/src/thread/pool.rs:61:29
  31: stdx::thread::Builder::spawn::{{closure}}
             at /home/lh/rust-src/rust-analyzer/crates/stdx/src/thread.rs:66:13
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 1:37:25 PM] Request callHierarchy/outgoingCalls failed.
  Message: request handler panicked: invalid offset
  Code: -32603 

@chanhx
Copy link

chanhx commented May 7, 2024

rust-analyzer version: 0.4.1951-standalone (c4618fe14 2024-05-05)
rustc version: rustc 1.76.0 (07dca489a 2024-02-04)
editor or extension: VSCode
repository link (if public, optional): chanhx/crabviz
code snippet to reproduce: Request callHierarchy/outgoingCalls on this method.

@Veykril The bug still exists in v0.4.1951.

thread 'Worker' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/line-index-0.1.1/src/lib.rs:111:35:
invalid offset
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_display
   3: core::option::expect_failed
   4: rust_analyzer::lsp::to_proto::range
   5: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
   6: rust_analyzer::handlers::request::handle_call_hierarchy_outgoing
   7: std::panicking::try
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 12:49:03 PM] Request callHierarchy/outgoingCalls failed.
  Message: request handler panicked: invalid offset
  Code: -32603 

@Veykril Veykril reopened this May 8, 2024
@Veykril Veykril self-assigned this May 8, 2024
@lh123
Copy link
Contributor Author

lh123 commented Jun 4, 2024

rust-analyzer version: 0.3.1983-standalone
rustc: 1.78.0 (9b00956e5 2024-04-29)

@Veykril I think this bug still exists

thread 'Worker' panicked at /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/line-index-0.1.1/src/lib.rs:111:35:
invalid offset
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_display
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:197:5
   3: core::panicking::panic_str
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:172:5
   4: core::option::expect_failed
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:1995:5
   5: rust_analyzer::lsp::to_proto::range
   6: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
   7: rust_analyzer::handlers::request::handle_call_hierarchy_outgoing
   8: std::panicking::try
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:53:40 AM] Request callHierarchy/outgoingCalls failed.
  Message: request handler panicked: invalid offset
  Code: -32603 

@Veykril Veykril reopened this Jun 4, 2024
@Veykril Veykril removed their assignment Jun 12, 2024
@bors bors closed this as completed in 0c61ffd Jul 7, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Jul 11, 2024
@springyworks
Copy link

springyworks commented Sep 26, 2024

error:
thread 'Worker' panicked at /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/line-index-0.1.1/src/lib.rs:111:35:
invalid offset

it happens sometimes when I use rust-analyzer its 'Show Call Hierarchy' in editor ; maybe because of my use of a local crate .?
[dependencies] burn = { path = "/home/etc..

release version:
rust-analyzer version: 0.3.2121-standalone
pre-release version:
rust-analyzer version: 0.4.2124-standalone

rustc version 1.83.0-nightly (363ae4188 2024-09-24)
Visual Studio Code - Insiders version: 1.94.0-insider on Ubuntu 24.04.1 LTS (aka noble)

@ChayimFriedman2
Copy link
Contributor

@springyworks That is... weird? They seem to be the same version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug I-panic
Projects
None yet
5 participants