nodeca / promise-memoize

Memoize promise-returning functions. Includes cache expire and prefetch.
MIT License
59 stars 7 forks source link

Cache not cleared, promises not resolved #7

Open Uko opened 5 years ago

Uko commented 5 years ago

Hi, I've spent quite some time debugging an issue in my app and it seems that there is a problem caused by memoization, and I would greatly appreciate any help to dig deeper.

My app runs on NodeJS 9.5. The main issue is that a memoized function never resolves, e.g.:

// getUser is memoized
// this does not log anything
getUser(email)
    .then((user) => console.log('Got user: ', user))
    .catch((err) => console.log('Got error: ', err))

The issue does not occur constantly and kicks in only after the app is running for some time.

Upon further investigation (debugging of memoizedFn), I noticed that the values from cache are not cleared after a specified timeout (10sec). When I clean the cache manually all works well for some time. E.g.:

I understand that that data I provided may be insufficient to identify the issue, but maybe you can suggest me where to look for more? For example, how can I compare what is the difference between a "healthy" key C and dead keys A, B, D?

puzrin commented 5 years ago

I don't know how described pattern is possible. Even if you have broken timer and dirty cache, it MUST return last successive promise.

I'd suggest to try this:

  1. Upgrade nodejs to 10.latest, to make sure no old bugs
  2. Use native promises (or try bluebird), if you used other implementation before
  3. Make sure getUser(email) is really a promise, not emulation with .then/.catch method
  4. Make sure number of objects you try to cache is not big (< 1000).
puzrin commented 5 years ago

Any news? I tend to close as unclear and not confirmed.