mike-lloyd03 / rudric

The Keeper of Secrets
MIT License
54 stars 2 forks source link

Database locked #45

Open Alt-iOS opened 7 months ago

Alt-iOS commented 7 months ago

Hi, when trying to open more than one terminal, I get an error saying my database is locked. I am also using it with direnv and tmux to open multiple panels, I am not sure what extra info I can provide to help debug/recreate the issue

direnv config [global] load_dotenv = true

rudric config default_shell = "zsh"

session_lifetime = "6h"

Alt-iOS commented 7 months ago

I am dumb, the issue is because of the parsing of the password as mentioned in the readme and tmux automatically opens all session in the same folder as when the session was originally opened, aka a folder with a trusted .envrc

mike-lloyd03 commented 7 months ago

Hey thanks for reporting this. I think this is still a valid issue. Or at least, a feature request. The app should probably handle the situation where there are concurrent attempts to read from the vault. Sqlite does have functionality for handling this but I'm not employing it evidently. I'll look into this.

mike-lloyd03 commented 7 months ago

Is this only happening when you're resurrecting a tmux session and your rudric session token is expired?

Rudric will delete expired keys from the database when this happens and I think Sqlite will lock the DB in this event.

Can you paste the full error you're getting here?

Alt-iOS commented 7 months ago

Sorry, I already uninstalled it because it was getting annoying and I could not work (literally could not use the terminal), tomorrow I will reinstall and try to reproduce and give more details into the issue, but it was more or less as follows:

  1. I am in a trusted project_dir with my rudric session open (using something like this for my token/session) export RUDRIC_SESSION=$(rudric session) and direnv loaded
  2. I use prefix+c to open another another window or prefix+% to divide my window in panes (happened on both cases), rudric ask for my master password, as tmux is opening the project_dir in another window
  3. I type the actual password (why btw idk why but it is visible when typing) and press enter, the terminal freezes
  4. I attempt to access my dir in another terminal window (because eh maybe its tmux that isn't playing nice), get frozen terminal again
  5. after a few minutes get an error saying something about the db getting locked

Also about the sqlite, it has a WAL journal mode which AFAIK helps avoid this kind of db locked stuff, this example is from the sqlx repo, but maybe if you could change your connection to something like the signature below, it would help

use sqlx::ConnectOptions;
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode};
use std::str::FromStr;

let conn = SqliteConnectOptions::from_str("sqlite://data.db")?
    .journal_mode(SqliteJournalMode::Wal)
    .read_only(true)
    .connect().await?;
mike-lloyd03 commented 7 months ago

Cool thanks for the pointers.

Something isn't playing nice between rudric and direnv and if you get prompted for a password, your keystrokes aren't getting passed into rudric so the process hangs. Though you should be able to abort it with ctrl-C.

I'm on Fish so I'm able to set a universal variable for all terminal sessions once per day with this:

set -Ux RUDRIC_SESSION (rudric session)

From that point onward, I don't have to keep entering my password to interact with the vault until the key expires. I'm not sure if Zsh has a similar universal variable functionality.

mike-lloyd03 commented 7 months ago

Hmmm... weird. I'm only getting a hanging terminal with direnv on fish. zsh, bash, and nu don't hang when prompted for a password with direnv.

You're also experiencing much different behavior than I am. For one, your password chars should be hidden. I'm not sure why they're showing for you. And two, the fact that you can enter chars at all but it only hangs when you hit enter is different. I wonder if rudric itself is getting stuck trying to unlock your vault.

After you hit enter, when the terminal is frozen, can you open another pane and see if the rudric process is running. pgrep rudric or something along those lines should tell you.

Finally, what kind of system are you running on?

Alt-iOS commented 7 months ago

Hi, I am running macos 14 on arm, I actually discovered the hang I get is because of this at the end of my zshrc source <(rudric env zsh) before killing it with pgrep rudric it shows my "password" and isnt bothered by the Ctrl+c sigkills

Screenshot 2024-03-10 at 9 29 30 PM

after killing it, it works normal

Screenshot 2024-03-10 at 9 30 43 PM
Alt-iOS commented 7 months ago

Hope this helps a little bit more in trying to diagnose the issue, and thanks for the help