Repository navigation
Description
Issue type:
[x] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
I've stambled on a quite strange problem here.
I was using a built-in cache using SQL for some time without any problem.
Latelly I've added a cache invaliadation on one of my entry types by:
qCache = getConnection().queryResultCache;
if (qCache !== undefined) {
qCache.remove([cache_id]).then(() => {
logger.info(`Kill cache id ${cache_id} invalidated`)
}).catch(err => {
logger.error(`Could not ivalidate cache ${err}`);
})
Which, broke everything in a strange way.
On production, once this is called for the first time, the problem happens
On my test environment, sometimes few cache invalidations are required.
What is broke?
After a call to remove the cache, all following calls to repositories (finds, inserts) just "hang".
They do not return at all, they do not try to contact SQL (all connections are sleeping).
No new connections are made.
I've checked the implementation of remove cache method and it's obviously a simple delete on a table, which makes this even stranger.
I have no idea how to debug it more, I'll try to prepare some proof-of-concept repo for this, but right now I'm askign if you guys have any "ideas" which I could check.
Sidenotes:
- My code creates up to 50-60 findMany on DB in short time
- In between them, some might invalidate cache that was used by previous one or will be used very soon by next one
- They are done one-by-one
- Each of this operation might be called async and merge with previous (which was not a problem before adding cache invalidate) (I'm reacting to events send to the system)
- Cache auto-invalidation by cache-life-time works as expected
Activity
pleerock commentedon Jan 6, 2019
Have no idea. Let's look on your reproduction example for me details. Best if you'll be able to create a PR with a failing test.
Kononnable commentedon Apr 20, 2019
Closing as no response from the author.
samie820 commentedon Aug 14, 2020
@Kononnable I ran into this same issue.
Calling
await getConnection().queryResultCache?.remove([user_related_entities_${user.id}])the first time works fine, but any other future call to it (in a Controller) hangs the process and I'm forced to restart nodephilefstat commentedon Aug 19, 2020
likewise - running into this issue, even in a simple script to sync configuration and remove the cached config.
pscarey commentedon Dec 11, 2020
Just adding another case of this. I think the issue should be re-opened.
SELECT 1times out, but that's obviously a slow process.pscarey commentedon Dec 11, 2020
Additional note, we're using the
ioredisdriver.pscarey commentedon Dec 12, 2020
Frustratingly, I've been unable to reproduce the issue at this stage within the testing framework of TypeORM based off our issue.
@philefstat @samie820 - would either of you be able to provide some additional info on what you were doing (possibly code snippets)?
MieszkoGulinski commentedon May 18, 2021
I have a similar issue, using PostgreSQL and default cache (with a SQL table for cache results). After several updates to a table and clearing cache after that, queries start getting stuck.
For the dataset size I had, it stopped getting stuck when I increased limit of simultaneous connections to PostgreSQL, using
extraparameter in connection settings, but I suspect that it'll stop working if we had more data.gdrbyKo1 commentedon Jan 21, 2022
This appears to be a bug in the implementation of
DbQueryResultCache.remove(). If the optionalqueryRunnerparameter is omitted, this method will allocate a new connection viaDbQueryResultCache.getQueryRunner(), but will never release the connection afterwards.On the other hand, the
DbQueryResultCache.storeInCachehandles this case correctly and will callqueryRunner.release()at the end if the caller didn't provide their ownQueryRunner.To workaround the issue, you can call
connection.createQueryRunner()on your own, pass the resulting query runner to theDbQueryResultCache.remove()call and then release it when.remove()resolves.