josephg / node-foundationdb

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

Last byte of string value is replaced by zero byte #40

Closed aikoven closed 4 years ago

aikoven commented 4 years ago

This started happening after updating to 0.10.4. I narrowed it down to a set of commands in Node REPL:

> const  fdb = require('foundationdb')
> fdb.setAPIVersion(600)
undefined
> db = fdb.openSync()
> db.set('key', '123')
Promise { <pending> }
> db.get('key').then(console.log)
Promise { <pending> }
> <Buffer 31 32 00>

It can be seen that the last byte became 00.

This doesn't happen if I pass Buffer.from('123') to the set() call.

josephg commented 4 years ago

Yikes thats really bad, and supports what I was saying here that we need to either remove the second code path (using strings) or add much more testing for it. Thanks for the report - I'll fix & publish an updated version now.

josephg commented 4 years ago

... The silver lining is that that test code would have crashed in 0.10.3 due to the Assertion failed: (owned == false) issue. Hopefully 0.10.4 is recent enough that nobody is using non-prefixed databases with string keys in production. (It wouldn't have worked at all with 0.10.3).

josephg commented 4 years ago

📦 foundationdb@0.10.6

aikoven commented 4 years ago

Yep, we updated to 0.10.4 because we started to experience these crashes. Haven't pushed it to production.

Thanks for the quick response!