posit-dev / positron

Positron, a next-generation data science IDE
Other
1.89k stars 55 forks source link

R crashing when editing long quarto files #3792

Open reuning opened 3 weeks ago

reuning commented 3 weeks ago

Positron Version:

Positron Version: 2024.06.1 build 17 Code - OSS Version: 1.90.0 Commit: 893521ef243f50fd4017232709c85086702b38d6 Date: 2024-06-25T03:05:41.077Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Linux x64 6.9.6-200.fc40.x86_64

Steps to reproduce the issue:

I'm having a strange issue and I'm sorry I cannot provide more details but what I am seeing is the R console randomly crashing with the following popping up: R 4.4.1 exited unexpectedly and was automatically restarted. You may have lost unsaved work. Exit code: 134 (I've coped more log info below). I'm working on a relatively long Quarto document (over 600 lines currently) and this seems to be part of it. If I copy part of the Quarto document into a new qmd file and edit it there then I don't have any crashes. But with the full file I do. I also do not necessarily have to be actively running anything or sending anything to the console for it to crash, it will just happen.

What did you expect to happen?

Were there any error messages in the output or Developer Tools console?

Below is copied from the Console R

[Positron] SEND heartbeat with timeout of 30 seconds
[R]   2024-07-02T00:09:38.010020Z ERROR  Requesting line 622 but only 597 lines exist. Document: '#

The R part of the quarto file (omitted for length)

[R] Backtrace:
[R]    0: ark::main::{{closure}}::{{closure}}
[R]    1: ark::main::{{closure}}
[R]    2: std::panicking::rust_panic_with_hook
[R]    3: std::panicking::begin_panic_handler::{{closure}}
[R]    4: std::sys_common::backtrace::__rust_end_short_backtrace
[R]    5: rust_begin_unwind
[R]    6: core::panicking::panic_fmt
[R]    7: ark::lsp::document_context::DocumentContext::new
[R]    8: ark::lsp::handlers::handle_hover
[R]    9: ark::lsp::main_loop::GlobalState::handle_event::{{closure}}
[R]   10: ark::lsp::main_loop::GlobalState::start::{{closure}}
[R]   11: tokio::runtime::task::core::Core<T,S>::poll
[R]   12: tokio::runtime::task::harness::Harness<T,S>::poll
[R]   13: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
[R]   14: tokio::runtime::scheduler::multi_thread::worker::Context::run
[R]   15: tokio::macros::scoped_tls::ScopedKey<T>::set
[R]   16: tokio::runtime::scheduler::multi_thread::worker::run
[R]   17: tokio::runtime::task::core::Core<T,S>::poll
[R]   18: tokio::runtime::task::harness::Harness<T,S>::poll
[R]   19: tokio::runtime::blocking::pool::Inner::run
[R]   20: std::sys_common::backtrace::__rust_begin_short_backtrace
[R]   21: core::ops::function::FnOnce::call_once{{vtable.shim}}
[R]   22: std::sys::pal::unix::thread::Thread::new::thread_start
[R]   23: start_thread
[R]   24: __GI___clone3
[R] 
[R]     at crates/ark/src/main.rs:488
[R] 
[Positron] SEND heartbeat with timeout of 30 seconds
[Positron] Shell socket disconnected from tcp://127.0.0.1:43463
[Positron] Heartbeat socket disconnected from tcp://127.0.0.1:47713
[Positron] Stdin socket disconnected from tcp://127.0.0.1:60497
[Positron] Control socket disconnected from tcp://127.0.0.1:46979
[Positron] I/O socket disconnected from tcp://127.0.0.1:45974
[Positron] All 5 sockets disconnected; kernel exited
[R] 
[Positron] R kernel status changed: idle => exited
[Positron] Connecting to R 4.4.1 kernel (pid 491361)
[Positron] Streaming log file: /tmp/kernel-PAfyrb/kernel.log
[Positron] Connecting to kernel sockets defined in /tmp/kernel-PAfyrb/connection.json...
[Positron] Control socket created (count = 1)
[Positron] Shell socket created (count = 2)
[Positron] Stdin socket created (count = 3)
[Positron] I/O socket created (count = 4)
[Positron] Heartbeat socket created (count = 5)
[Positron] Control socket connecting to tcp://127.0.0.1:45336...
[Positron] Shell socket connecting to tcp://127.0.0.1:43345...
[Positron] Stdin socket connecting to tcp://127.0.0.1:53179...
[Positron] I/O socket connecting to tcp://127.0.0.1:46139...
[Positron] Heartbeat socket connecting to tcp://127.0.0.1:49103...
[Positron] Control socket connected to tcp://127.0.0.1:45336
[Positron] Stdin socket connected to tcp://127.0.0.1:53179
[Positron] Shell socket connected to tcp://127.0.0.1:43345
[Positron] Heartbeat socket connected to tcp://127.0.0.1:49103
[Positron] I/O socket connected to tcp://127.0.0.1:46139
[Positron] Establishing socket listeners...
[Positron] Received initial heartbeat: heartbeat

I've also see errors like:

[R]   2024-07-02T00:22:45.456578Z ERROR  Panic! In file 'crates/ark/src/lsp/document_context.rs' at line 32: Failed to find closest node to point: (603, 0) with contents '#

This seems to come about when I am highlighting and CTRL+Enter sending something to the console to run.

lionel- commented 3 weeks ago

Would you be able to share with us this quarto file?

reuning commented 3 weeks ago

So I've been working with this file for a few hours this morning and not had any problems. I'm a bit baffled by what was happening. Here is a copy of what was causing issues if it helps, but if you want to close this I get it as well.

For the record I did try opening and closing Positron yesterday and it didn't solve the problem, not sure what I did that solved it now.

DavisVaughan commented 3 weeks ago

@lionel- I've seen this one other time, also with Quarto https://github.com/posit-dev/positron-beta/discussions/227

I've never seen it in an R script, so it makes me think something is wrong with the .qmd->.R mapping, not with our ark lsp code