Repository navigation
Closed
nushell/reedline
#536Labels
A:database-SQLOur interactions with sqlite and any other work to interface with databases.A:line-editorIssues related to reedlinecategory:bugSomething isn't working
Description
Describe the bug
when i add
history: {
file_format: "sqlite"
}to my config.nu, nushell creates ~/.config/nushell/history.sqlite3 to hold the history
however, running history --clear and then nu does not work and gives
Error:
× error within history database: SqliteFailure(Error { code: SystemIoFailure, extended_code: 522 }, Some("disk I/
│ O error"))Note
this behaviour does not appear 100% of the time, but most of it
a quick fix is to remove the .sqlite3 files generated by history --clear
> ls ~/.config/nushell/history.sqlite3-* | get name
╭───┬───────────────────────────────────────────────────╮
│ 0 │ /home/amtoine/.config/nushell/history.sqlite3-shm │
│ 1 │ /home/amtoine/.config/nushell/history.sqlite3-wal │
╰───┴───────────────────────────────────────────────────╯How to reproduce
- live inside
nushell - remove the history with
history --clear - try to open a new terminal or run
nufrom current session - see the terminal crash or the error above
Expected behavior
i do not know what these history.sqlite3-shm and history.sqlite3-wal are here for, but they appear to block the startup of nushell...
maybe they shouldn't be here? 🤔
in the end i really would not want to have no shell nor any terminal...
if i'd close all my terminals after this first history --clear i would have had to drop into a TTY to fix nushell manually, that would have been definitely scary 😱
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.75.0 |
| branch | |
| commit_hash | 17a265b |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.66.1 (90743e729 2023-01-10) |
| rust_channel | 1.66.1-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.66.1 (ad779e08b 2023-01-10) |
| pkg_version | 0.75.0 |
| build_time | 2023-02-04 13:06:35 +01:00 |
| build_rust_channel | release |
| features | database, default, trash, which, zip |
| installed_plugins | gstat, len, my_str_len, nu-example-1, nu-example-2, nu-example-3, pnet, query, query json, query web, query xml |
Additional context
No response
Metadata
Metadata
Assignees
Labels
A:database-SQLOur interactions with sqlite and any other work to interface with databases.A:line-editorIssues related to reedlinecategory:bugSomething isn't working
Activity
fdncred commentedon Feb 6, 2023
I thought
--clearwas actually just removing the file itself. I wonder if the problem is that it's only removing the sqlite3 file but not removing all 3 sqlite files, i.e. the sqlite3 file, the wal file and the shm file.amtoine commentedon Feb 7, 2023
looks this is exactly the issue 👍
at least i can reproduce this behaviour each time it crashes 👌
Fixes nushell#7991 sqlite3 auxiliary files deletion
Fixes nushell#7991 sqlite3 auxiliary files deletion
rgwood commentedon Feb 8, 2023
FYI I'm working on an improvement to reedline to fix this: nushell/reedline#536
amtoine commentedon Feb 9, 2023
amazing 🤩
is there a revision of
nushellon which i can checkout and try to see if the bug still appears? 😌maybe the latest
mainon 16b99ed? not sure how the two interact, i think your change will need to be in[email protected](as written inCargo.toml) to take effect 🤔rgwood commentedon Feb 9, 2023
Not yet. Need to wait for a new version of reedline to be published (I'm not sure how to do that; @sholderbach do you mind walking me through it sometime?) and then I'll submit a PR here to use the new Reedline functionality.
1 remaining item
rgwood commentedon Feb 9, 2023
Ah cool, I assumed we were pulling in published versions. Will take a look.
rgwood commentedon Feb 9, 2023
After fighting with error conversions for half an hour I thought I had it working, and... ugh:

Very weird that it would kill Nushell without a stack trace. I'm gonna clear my mind and come back to this another time 🧘
fdncred commentedon Feb 9, 2023
I was trying to help out here because I had an idea of trying to repro this in reedline. I wanted to see if reedline would puke too when clearing in repl mode. I was thinking something was pulling on it and not expecting 0 records.
So, I added this to
demo.rsaround line 151.and I added this to
engine.rsaround like 414.It all compiles and works. :( I can't seem to get it to fail, even when writing to a real db.
rgwood commentedon Feb 9, 2023
Thanks for taking a look at that. This is my WIP: 7260a11
Very strange that it crashes entirely. Maybe something in
evaluate_repl()?fdncred commentedon Feb 10, 2023
I've been reading a little bit about sqlite. I'm wondering if we need to do a checkpoint and vacuum at some interval or on exit. I also didn't realize the deleting doesn't delete, it just frees the pages.
Here's the link I was reading in. I was mostly searching for a reason why the wal and shm don't remove themselves on exit.
https://dzx.fr/blog/understanding-sqlite/#maintain-the-database
rgwood commentedon Feb 10, 2023
Hmm, good question. I don't believe that's necessary for correctness, but it may be necessary to ensure that the deleted history is truly gone from disk (i.e. unrecoverable by looking through the WAL)
fdncred commentedon Feb 10, 2023
just documenting here for searching later. i used this command to cleanup my wal and shm files.
my wal and shm files are normal size now.
rgwood commentedon Feb 11, 2023
Used a debugger and confirmed that this is where Nu exits the REPL loop on my branch:
nushell/crates/nu-cli/src/repl.rs
Line 589 in 7103497
Still figuring out the best way to fix this. It's unfortunate that the
Reedlinestruct contains ahistory_last_run_idfield instead of delegating all history management to theHistorystruct.NotTheDr01ds commentedon Dec 6, 2024
Given the challenges folks seem to have encountered trying to resolve this, is this still a
good-first-issue?kronberger-droid commentedon Nov 13, 2026
Fixed by #19092.
history --clearclears the sqlite history with SQL now and no longer deletes the database file, so the-waland-shmfiles can't be left behind without it.I checked it on 0.117 with several sessions open, a new
nustarts fine after clearing.