-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regex high memory utilisation #7482
Comments
Thanks @aboudreault for the detailed analysis, we will try to look into reproducing this and have a discussion about fixes. |
Is there any update on this issue? |
@PaulFischer-Kong could you take a look and see if we can arrange some priority for this issue? |
Is this still an issue with Kong 3.x? |
This has been fixed. Please upgrade to Kong 3.1.0 or above. |
Summary
It was reported by some customers that in some circumstances, kong can have a rapid memory utilisation increase. In only 5-10 minutes, a node can grow to 15-20G of memory. This can happen when:
Steps To Reproduce
while true; do curl -vk https://localhost:8443/doesntexist; done
.Behind the hood, everytime kong receives a query, it tries to match it against all existing regex uris: https://github.com/Kong/kong/blob/master/kong/router.lua#L1565
Since the route doesn't exist... it calls re_find on all of them, which makes the openresty regex module automatically tries to compile and cache it in its internal lrucache. At the same time, it replaces and removes many keys (pointers). However, the cdata memory (pcre) is not freed right away. This will happen eventually when the garbage collector is triggered and call the ffi GC finalizers. When the traffic is low... the garbage collector doesn't seem to react fast enough to avoid an important memory grow caused by the internal cdata. In some envs (like k8s), nodes are simply killed.
Resolution
The resolution to avoid this issue is to make sure most of the regex URIs can fit in the cache: increasing lua_regex_cache_max_entries.
Improvements
o
flag (compile) when we detect we are just iterating too many regex_uris: https://github.com/Kong/kong/blob/master/kong/router.lua#L1564The text was updated successfully, but these errors were encountered: