nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
546 stars 154 forks source link

Occasional panics with SQLite history #480

Open kubouch opened 2 years ago

kubouch commented 2 years ago

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 commented 2 years ago

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

kubouch commented 2 years ago

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

kubouch commented 2 years ago

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"))
phiresky commented 2 years ago

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)

kubouch commented 2 years ago

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 commented 2 years ago

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.

phiresky commented 2 years ago

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.