Bad Decoder state
soheilpro opened this issue · comments
Sometimes I get this error in my app when I use a cached instance of the Decoder class:
Error: The type of key must be string or number but object
at Decoder.doDecodeSync (/usr/app/src/node_modules/@msgpack/msgpack/dist/Decoder.js:383:31)
at Decoder.decode (/usr/app/src/node_modules/@msgpack/msgpack/dist/Decoder.js:83:29)
at FileCacheStorage.get (/usr/app/src/app_out/cache/file-cache.js:20:33)
at async Cache.get (/usr/app/src/app_out/cache/index.js:21:23)
at async Promise.all (index 8)
at async process (/usr/app/src/app_out/www/routers/user.js:37:167)
at async /usr/app/src/app_out/www/routers/user.js:20:5
at async wrappedMiddleware (/usr/app/src/node_modules/@awaitjs/express/index.js:116:7)
It goes away when I restart the app.
Looks like the Decoder.reinitializeState() method is failing to reset some vars.
Thanks for reporting it. I'll investigate it this week.
It would be great if you have a minimum reproducible code.
Unfortunately, I'm not able to create a reproducible code.
This is all I'm doing in my Node app:
const encoder = new Encoder();
const decoder = new Decoder();
function saveToCache(entry, key) {
const buffer = encoder.encode(entry);
// write buffer to file
}
function readFromCache(key) {
// read buffer from file
return decoder.decode(buffer);
}
Thanks for the code. Looks like you reuse the instances of Encoder and Decoder. It's a big hint.
Yes.
It's a web app. I create them once and use them for all the requests.