josephg / node-foundationdb

Modern Node.js FoundationDB bindings
Other
115 stars 17 forks source link

`directory.open` fails with error "The given prefix is already in use" #63

Closed aikoven closed 2 years ago

aikoven commented 2 years ago

I'm getting sporadic errors that say "The given prefix is already in use" when I'm trying to open a directory using

fdb.directory.open(db, name);

As far as I can see from the code, we only get to that branch when the prefix is explicitly specified. So this is probably due to the fact that we write to the prefix variable that is out of the scope of the transaction body, so its value gets preserved through transaction retries.

I've checked the same function in Python implementation and found that the prefix variable there lives inside the scope of the transaction.

josephg commented 2 years ago

Hmmm nice find. Can you make a test case that reproduces the issue? I’d like to make sure we fix the problem and that it doesn’t happen again.

josephg commented 2 years ago

Meanwhile I've published foundationdb@1.1.3, which should fix the issue. Give it a try and let me know.

The bug looks straightforward even though its a bit of a nightmare to test. Ideally I'd like to add a unit test for this fix too - but I'm feeling a bit lazy.

aikoven commented 2 years ago

Thanks for the fix.

I added a test case in #64 that failed 10 out of 10 times with 1.1.2. It passes with 1.1.3.

josephg commented 2 years ago

Awesome - nice one! Thanks for tracking this down and reporting.