Kong / kong-python-pdk

Write Kong plugins in Python (Experimental)
Apache License 2.0
40 stars 14 forks source link

Memory leak in server.py #120

Closed vtlkvl closed 1 year ago

vtlkvl commented 1 year ago

We ran into a memory leak in Kong Plugin Server that can be reproduced as described in https://github.com/vtlkvl/kong-python-pluginserver-memory-leak. We figured out that for each plugin call the messaging queue is added to PluginServer.events in PluginServer.handle_event, but PluginServer._step and specifically removal of the queue is done just for the last plugin. So if you have 10 plugins, 10 queues will be added to PluginServer.events, but just 1 will be deleted and 9 will remain in the memory and never get GCed. As a result PluginServer.events will grow until OOM.

vtlkvl commented 1 year ago

@fffonion I've got a fix for the issue. Can I get write access to push a feature branch to make a PR?

fffonion commented 1 year ago

@vtlkvl we usually don't grant access to community contributers, please creeate a fork and create PR from there : ) Feel free to ping me when it's ready.

Very good analysis on the memory issue btw 👍

vtlkvl commented 1 year ago

@fffonion I've made a PR. Once it is approved and merged, how long does it take to get a new version?

fffonion commented 1 year ago

@vtlkvl I will release a new version once the PR is merged!

vtlkvl commented 1 year ago

It should be resolved in Kong PDK 0.35.