reedline icon indicating copy to clipboard operation
reedline copied to clipboard

Occasional panics with SQLite history

Open kubouch opened this issue 2 years ago • 7 comments

Platform Linux Terminal software tmux

Describe the problem you are observing.

Steps to reproduce

Happens with history set to sqlite.

Unfortunately, I don't have 100% repro steps but reedline seems to panic when I have one Nushell open, then open another one in a Slurm interactive session, work for a while, then try to bring up a history entry with the "up" key.

The panic happens at this line https://github.com/nushell/reedline/blame/70118f732c974fd953356020c6b3eb9b6ebe1ee0/src/engine.rs#L1007 where it says "todo: error handling". The expect() should be cleared up.

Screenshots/Screencaptures

thread 'main' panicked at 'todo: error handling: ReedlineError(HistoryDatabaseError("SqliteFailure(Error { code: NotADatabase, extended_code: 26 }, Some(\"file is not a database\"))"))', /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/70118f7/src/engine.rs:1007:14

kubouch avatar Sep 16 '22 08:09 kubouch

Seems to be introduced with https://github.com/nushell/reedline/pull/401

kubouch avatar Sep 16 '22 09:09 kubouch

It seems the history database somehow gets corrupted. When I try to open-db it, it shows an error "Not a SQLite file".

kubouch avatar Sep 16 '22 09:09 kubouch

Trying to run nu with the corrupted database results in

Error:
  × error within history database: SqliteFailure(Error { code: NotADatabase, extended_code: 26 },
  │ Some("file is not a database"))

kubouch avatar Sep 16 '22 09:09 kubouch

Is your home directory on a network drive by any chance? If so, which one and with which mount options. It should be pretty hard to corrupt an SQLite database, the only instances I've myself had before were when on a network drive, opened from multiple computers, with a NFS mount option such as nolock. It might also be helpful if you could send an example corrupted file (publicly or via email)

phiresky avatar Sep 18 '22 16:09 phiresky

It was on a compute cluster (that I do not administer) that has many nodes so it is quite possible it was due to some mounting etc.

kubouch avatar Sep 20 '22 08:09 kubouch

Since it might be hard to track down the cause, I think the panic should first be patched ASAP with some error handling, then we can move on to figuring out why the database got corrupted.

kubouch avatar Sep 20 '22 09:09 kubouch

Could there also maybe be some corruption resulting due to threading or something within reedline? I'm not sure if rusqlite is really safe regarding that.

phiresky avatar Sep 20 '22 18:09 phiresky