Bug: axios.waiting
grows when the max entries is set + etag handling
#833
Labels
bug
Something isn't working
good first issue
Good for newcomers
help wanted
Extra attention is needed
What happened?
Hey Arthur,
Recently we've migrated our code to axios and we've used your package to handle caching. Thank you for your work here ❤️
After the migration, we've noticed that memory consumption of our app presents a "lovely" toothsaw pattern 😬 I've spent quite a lot of time trying to figure out what's wrong.
Here is the recap - sorry for it being long.
Etag / last-modified
This is not a bug, but that caused us to store many entries forever.
Every resource with an etag header (or last-modified) in the response (the default express app adds it), is kept forever, and there is no simple way to disable it (or I haven't found one).
I've mitigated it with the following code that removes those headers and assign default stale ttl:
waiting
To mitigate the problem with stalled entries kept forever, we've tried using
MAX_ENTRIES
in the memory storage, but that didn't improve the situation but the problem was different.Where we have many parallel requests fired, and we exceed the max entries limit, the memory adapter removes some of them. But they are kept in the
axios.waiting
object. After the request is resolved they are not removed from there. Probably until you try to hit the same request.id again (the same url, method, query).I believe the problem comes from this part of the code:
axios-cache-interceptor/src/interceptors/response.ts
Lines 93 to 108 in f0ba5ad
Because when you're removing the entry from the storage and it's not there, the returned value is
so this if is true, so we end the response interceptor, and we do not remove / resolve other waiting requests.
In our very specific case, the URL passed to Axios was sliced from a very long document, which caused Node to keep the reference to the original string. (slice / substring / regex match, does not create the copy of a string, but points to the fragment of the original string).
proof of concept
Here is my repo with test cases describing the two issues we had:
https://github.com/bukowskiadam/axios-cache-interceptor-memory-issue
I hope it gives some working example so you can validate the problems.
What's next
(In other words: what is this issue about)
axios.waiting
memory leaketag: false
to disable handling ETag headers.Best regards,
Adam
axios-cache-interceptor version
v1.5.2
Node / Browser Version
Node v20.12.2
Axios Version
v1.6.8
What storage is being used
Memory Storage
Relevant debugging log output
The text was updated successfully, but these errors were encountered: