`Console::get_mut()` should use `CONSOLE.try_with()`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 337
- Forks
- 32
- Avg merge
- 8d 17h
- Merged PRs (30d)
- 11
Description
I just ran into https://github.com/posit-dev/ark/pull/1222/changes/b6e980d5efb7f4ce865bfc8cd58792b6da6139bc with this panic message
cannot access a Thread Local Storage value during or after destruction: AccessError
What happened was:
CONSOLEwas destructing as R shut downCONSOLE.pending_futureswas destructed viaCONSOLEdestructing- One of the
pending_futureswas created with capture support, i.e. withConsoleOutputCaptureenabled ConsoleOutputCapture::dropwas run as the future destructed. This tried to re-accessCONSOLEviaConsole::get_mut(). ButCONSOLEis destructing! So we get a panic.
We should analyze this and figure out the most robust solution.
For my use case, I was accidentally holding a permanently running RTask with capture support, so the easy solution for me was to just turn off capture support, avoiding ConsoleOutputCapture::drop from running.
But I think in theory that even short running futures with capture support that just so happen to be in pending_futures when R restarts and CONSOLE destructs can cause this to happen.
So maybe we need to be able to call something like Console::try_get_mut() from this location, which would use CONSOLE.try_with() instead of CONSOLE.with_borrowed_mut(). I think you can build a form of try_with_borrowed_mut() by looking at the definition of with_borrowed_mut() and replacing the .with() with .try_with().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Console::get_mut(), with_borrowed_mut(), and ConsoleOutputCapture::drop, then trace how pending_futures are destroyed while CONSOLE is shutting down. Reproduce or test the capture-enabled future cleanup path and ensure destruction does not panic when CONSOLE is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100