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

R crashing when editing long quarto files #3792

Closed
Tracked by #4858
reuning opened this issue Jul 2, 2024 · 18 comments
Closed
Tracked by #4858

R crashing when editing long quarto files #3792

reuning opened this issue Jul 2, 2024 · 18 comments
Labels
area: quarto Issues related to Quarto category. bug Something isn't working investigate Needs initial, limited investigation to prioritize lang: r support

Comments

@reuning
Copy link

reuning commented Jul 2, 2024

Positron Version:

Positron Version: 2024.06.1 build 17
Code - OSS Version: 1.90.0
Commit: 893521e
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.

@reuning reuning added the bug Something isn't working label Jul 2, 2024
@lionel- lionel- added lang: r area: kernels Issues related to Jupyter kernels and LSP servers labels Jul 2, 2024
@lionel-
Copy link
Contributor

lionel- commented Jul 2, 2024

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

@reuning
Copy link
Author

reuning commented Jul 2, 2024

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
Copy link
Contributor

DavisVaughan commented Jul 2, 2024

@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

@lionel- lionel- added area: quarto Issues related to Quarto category. and removed area: kernels Issues related to Jupyter kernels and LSP servers labels Jul 3, 2024
@juliasilge juliasilge added this to the Release Candidate milestone Jul 8, 2024
@juliasilge juliasilge added the investigate Needs initial, limited investigation to prioritize label Jul 8, 2024
@juliasilge
Copy link
Contributor

We suspect #4437 may be other examples of problems with this Quarto "mapping" from .qmd to .R.

@reuning
Copy link
Author

reuning commented Oct 12, 2024

Just wanted to follow up and maybe provide a more minimal example. I think there is an issue when R code starts immediately in a code block.

I was able to get R to crash using just the qmd below, and it keeps crashing over and over again.

---
title: "Test"
---

## Section 1

```{r}

set.seed(1)
sample(1)

```

## Section 2

```{r}
set.seed(1)
sample(1)

```


```{r}

set.seed(1)
sample(1)

```

Info:
Positron Version: 2024.10.0 build 13
Code - OSS Version: 1.93.0
Commit: 34b5c57
Date: 2024-10-03T16:22:08.586Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Linux x64 6.10.11-200.fc40.x86_64

@juliasilge
Copy link
Contributor

Thank you for sharing this @reuning! Can you share a set of steps that causes a crash for you? I have loaded up your document here that you shared. Can you outline a set of steps (maybe starting from a fresh open of Positron with this file in the workspace) that causes a crash for you?

@reuning
Copy link
Author

reuning commented Oct 20, 2024

I've been trying to figure out the minimal thing that will get this to happen. And I think it is most likely to happen if you've run one code chunk and then create another one.

What I did, starting with an empty file is write out:

---
output: html
---

```{r}
sample(1)

```

I then ran the code sample(1) the chunk once (highlighting it and hitting Ctrl+Enter).

Then I created a new block below so the full qmd looked like:

---
output: html
---

```{r}
sample(1)

```

```{r}
sample(2)

```

At this point I highlighted the sample(2) line and hit Ctrl+Enter and had an immediate crash.

Here is the log:

2024-10-20 11:12:42.045 [info] [R] *** Log started at Sun Oct 20 11:12:41 AM EDT 2024
2024-10-20 11:12:42.045 [info] [R] *** Command line:
2024-10-20 11:12:42.045 [info] [R] /usr/share/positron/resources/app/extensions/positron-r/resources/ark/ark --connection_file /tmp/kernel-SiqND2/connection.json --log /tmp/kernel-SiqND2/kernel.log --startup-file /usr/share/positron/resources/app/extensions/positron-r/resources/scripts/startup.R --session-mode console -- --interactive --no-restore-data
[R]   2024-10-20T15:13:20.549914Z ERROR  Requesting line 12 but only 11 lines exist.
[R] 
[R] Document:
[R] #
[R] #
[R] #
[R] #
[R] #
[R] sample(1)
[R] 
[R] #
[R] #
[R] #
[R] 
[R] 
[R] Backtrace:
[R]    0: <unknown>
[R]    1: <unknown>
[R]    2: <unknown>
[R]    3: <unknown>
[R]    4: <unknown>
[R]    5: <unknown>
[R]    6: <unknown>
[R]    7: <unknown>
[R]    8: <unknown>
[R]    9: <unknown>
[R]   10: <unknown>
[R]   11: <unknown>
[R]   12: <unknown>
[R]   13: <unknown>
[R]   14: <unknown>
[R]   15: <unknown>
[R]   16: start_thread
[R]   17: __clone3
[R] 
[R]     at crates/ark/src/lsp/encoding.rs:86
[R] 
[R]   2024-10-20T15:13:20.553827Z ERROR  Panic! In file 'crates/ark/src/lsp/document_context.rs' at line 32: Failed to find closest node to point: (11, 0) with contents '#
[R] #
[R] #
[R] #
[R] #
[R] sample(1)
[R] 
[R] #
[R] #
[R] #
[R] '
[R] 
[R] Backtrace:
[R]    0: <unknown>
[R]    1: <unknown>
[R]    2: <unknown>
[R]    3: <unknown>
[R]    4: <unknown>
[R]    5: <unknown>
[R]    6: <unknown>
[R]    7: <unknown>
[R]    8: <unknown>
[R]    9: <unknown>
[R]   10: <unknown>
[R]   11: <unknown>
[R]   12: <unknown>
[R]   13: <unknown>
[R]   14: <unknown>
[R]   15: <unknown>
[R]   16: <unknown>
[R]   17: <unknown>
[R]   18: <unknown>
[R]   19: <unknown>
[R]   20: <unknown>
[R]   21: <unknown>
[R]   22: <unknown>
[R]   23: start_thread
[R]   24: __clone3
[R] 
[R]     at crates/ark/src/main.rs:281
[R] 

@DavisVaughan
Copy link
Contributor

I tried this a few times but still can't reproduce 😢 . I've also spent a decent chunk of time on both mac and windows trying to reproduce this with a long quarto doc but no luck

@juliasilge
Copy link
Contributor

juliasilge commented Oct 22, 2024

So I don't keep having to look this up, we have had users report this on:

Most reports are on quite long .qmd files, but unfortunately @reuning is able to generate the crash with a pretty minimal file.

@reuning can you tell me in even more detail what you mean by this?

highlighting it and hitting Ctrl+Enter

Do you use your mouse to highlight a line of code? vs. put your cursor in a line and then use the keyboard shortcut? It might be helpful to have even more detail about what actions you are taking.

@reuning
Copy link
Author

reuning commented Oct 22, 2024

This might be too much but I screen recorded it and put it up on dropbox here.

In this case it happens when I highlight it with my cursor and then use the keyboard shortcut to run that line.

I also just left my cursor on that line and ran it and had the same crash (without highlighting).

Also this only seems to happen if I run the first block and then write out the second block. If I load the qmd file with both blocks I can run each block fine.

@juliasilge
Copy link
Contributor

Thank you for sharing that video! I tried to match as closely as possible what you did and unfortunately still don't see the crash. 😩

These questions are me trying to be thorough, not necessarily thinking one of them is really the problem:

  • I notice you are not working in a workspace in this video. Do you observe this problem both in/not in a workspace?
  • What gesture are you using to highlight the code before you send it to the console? Your mouse? Shift+Arrow? Something else?
  • I notice you have output: html, which is valid .Rmd but not .qmd front matter (you would say format: html for Quarto). Have you observed the problem if you say format: html instead?
  • Do you mind sharing what other extensions you have installed, beyond those that are bundled in Positron?

@DavisVaughan
Copy link
Contributor

DavisVaughan commented Oct 23, 2024

One somewhat interesting thing I noticed - it seems like there is not a trailing newline in the file (i.e. the ``` is the very last line). Same for the video here #3945 (comment)

I haven't been able to reproduce even after setting "files.insertFinalNewline": false, but that seems a little suspicious

@DavisVaughan
Copy link
Contributor

If you could also post your settings.json, I think that would be quite helpful. It's very possible that a setting is affecting saving/formatting/hover that causes the issue.

@reuning
Copy link
Author

reuning commented Oct 23, 2024

Okay so I've tried a few things:

  • I can recreate this in a workplace
  • I am double clicking to highlight code.
  • Having it as format: html also causes this.

I've been able to get it to crash consistently by just typing out this:

---
format: html
---

```{r}
sample(1)
```

```{r}
sample(2)
```

The strange thing is that if I open up that file and just highlight and run things it will run fine. It only happens when I start from scratch and type it out.

My settings:

{
    "window.customTitleBarVisibility": "auto",
    "workbench.colorTheme": "Catppuccin Macchiato",
    "cSpell.enabledFileTypes": {
        "quarto": true
    },
    "latex-workshop.latex.autoClean.run": "onSucceeded",
    "python.defaultInterpreterPath": "/usr/bin/python",
    "security.workspace.trust.untrustedFiles": "open"
}

Extensions

Name: Catppuccin for VSCode
Id: Catppuccin.catppuccin-vsc
Description: 🦌 Soothing pastel theme for VSCode
Version: 3.15.2
Publisher: Catppuccin
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=Catppuccin.catppuccin-vsc

Name: Code Spell Checker
Id: streetsidesoftware.code-spell-checker
Description: Spelling checker for source code
Version: 4.0.14
Publisher: Street Side Software
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=streetsidesoftware.code-spell-checker

Name: LaTeX Workshop
Id: James-Yu.latex-workshop
Description: Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
Version: 10.5.5
Publisher: James-Yu
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=James-Yu.latex-workshop

Name: Rainbow CSV
Id: mechatroner.rainbow-csv
Description: Highlight CSV and TSV files, Run SQL-like queries
Version: 3.3.0
Publisher: mechatroner
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=mechatroner.rainbow-csv

@juliasilge
Copy link
Contributor

We have a possible fix for you to try out @reuning. Can you please try:

@reuning
Copy link
Author

reuning commented Oct 25, 2024

It looks to be working now.

I tried what I did above and didn't have any crashes. Played around with a longer Quarto file as well and didn't have any crashes with that either.

Thank you all.

@juliasilge
Copy link
Contributor

Thank you so much for your patience and willingness to share so much feedback! ❤

@juliasilge
Copy link
Contributor

juliasilge commented Oct 29, 2024

We've got another new dev version of the Quarto extension here with a cleaned-up version of the fix, if you would like to again download, unzip, and install the .vsix: https://github.com/quarto-dev/quarto/actions/runs/11581960140

We will do an official release of the Quarto extension with this fix probably before the end of the week.

Since we don't have an internally reproducible way of generating the original problem, I am going to move this issue straight to "Done" (no QA verification). I used the .vsix from main as of now to run through normal Quarto workflows, and all appears to be working well! Thank you again for your feedback and patience. 🙌

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: quarto Issues related to Quarto category. bug Something isn't working investigate Needs initial, limited investigation to prioritize lang: r support
Projects
None yet
Development

No branches or pull requests

5 participants