level-ttl icon indicating copy to clipboard operation
level-ttl copied to clipboard

Race condition

Open ralphtheninja opened this issue 7 years ago • 5 comments

screenshot from 2018-06-30 22-14-30

ralphtheninja avatar Jun 30 '18 20:06 ralphtheninja

@ralphtheninja https://github.com/sinonjs/lolex might be useful for the tests here

vweevers avatar Jul 13 '18 10:07 vweevers

I left level-ttl for a while, but want to go back to it once we're done with abstract-leveldown.

ralphtheninja avatar Jul 13 '18 10:07 ralphtheninja

Good news: it looks like the recent changes in leveldown (deferring close with pending put or iterator, or something else) decreases the likelihood of the race issue. If I change the tests to use memdown the race issue happens more often.

That gives us a lead.

vweevers avatar Apr 06 '19 11:04 vweevers

Correction, memdown failed tests because its iterator yields a different key type than leveldown. Trying to figure out why - before further investigating the race issue because there could be a larger issue in subleveldown or other.

vweevers avatar Apr 06 '19 12:04 vweevers

Okay. The "problem" with memdown is that, when wrapped with encoding-down and the utf8 encoding and you put() a Buffer, then you'll always get back a Buffer because memdown only uses keyAsBuffer to determine whether it should convert a stored string to a requested Buffer (when keyAsBuffer is true), and not whether to convert a stored Buffer to a string (when keyAsBuffer is false, which is the case with the utf8 encoding).

See https://github.com/Level/community/issues/58#issuecomment-487354041 for an illustration.

I could argue that this makes sense - typically you want the output type to match the input type and level-ttl is at fault for mixing string and Buffer keys - but in any case it's not a situation we can escape from atm. So, long story short, level-ttl (or at least its tests, because it looks like the problem only applies to internally used keys) should take care to convert keys to whatever type is expected.

vweevers avatar Apr 06 '19 13:04 vweevers