Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible race condition when adding entries #185

Open
DamionD opened this issue Aug 17, 2020 · 2 comments
Open

Possible race condition when adding entries #185

DamionD opened this issue Aug 17, 2020 · 2 comments
Assignees

Comments

@DamionD
Copy link

DamionD commented Aug 17, 2020

I have found the following issue when adding multiple entries to a KeePass database stored on an SMB share:

@(1..9) | %{ New-KeePassEntry -KeePassEntryGroupPath "Test" -DatabaseProfileName "Test" -MasterKey $Password -Title "Test$($_)" -UserName "Test$($_)" -KeePassPassword $Password }

Add-KpEntry : Exception calling "Save" with "1" argument(s): "The process cannot access the file '\\SERVER\Share\Test.kdbx' because it is being used by another process."
At C:\Program Files\WindowsPowerShell\Modules\PoshKeePass\2.1.3.0\PoShKeePass.psm1:793 char:13
+             Add-KpEntry @addKpEntrySplat | ConvertTo-KPPSObject -Data ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-KPEntry], MethodInvocationException
    + FullyQualifiedErrorId : IOException,Add-KPEntry

The process manages to add 1 to 4 of the entries before failing. Adding the entries individually works normally, as it does if I add a delay:

@(1..9) | %{ New-KeePassEntry -KeePassEntryGroupPath "Test" -DatabaseProfileName "Test" -MasterKey $Password -Title "Test$($_)" -UserName "Test$($_)" -KeePassPassword $Password; Start-Sleep -Milliseconds 15 }

The minimum delay that appears to be needed is 11 milliseconds.

EDIT: The delay required seems to increase with the number of entries being processed (and possibly network latency).

@jkdba
Copy link
Member

jkdba commented Sep 2, 2020

@DamionD It might be curious to setup a file watcher to ensure that there isn't something else scanning your file or utilizing it in some capacity that may cause the blocking.

In my setup I also have the DB on a CIFS and very occasionally I will get a write error with the same message when I have one process trying to write (typically me on command line) and other automated processes are accessing the DB of which I probably have 100s of calls a minute.

It could be the sleep is just spacing out your calls enough to avoid the other potential processes.

Can you replicate this on a test DB that is not used by anything else?

@jkdba jkdba self-assigned this Sep 2, 2020
@DamionD
Copy link
Author

DamionD commented Sep 7, 2020

@DamionD It might be curious to setup a file watcher to ensure that there isn't something else scanning your file or utilizing it in some capacity that may cause the blocking.

In my setup I also have the DB on a CIFS and very occasionally I will get a write error with the same message when I have one process trying to write (typically me on command line) and other automated processes are accessing the DB of which I probably have 100s of calls a minute.

It could be the sleep is just spacing out your calls enough to avoid the other potential processes.

Can you replicate this on a test DB that is not used by anything else?

Hi @jkdba, this testing was performed on a brand new test database. The SMB server has Sophos anti-virus with on-demand scanning enabled; could this be relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants