Kong / kong-python-pdk

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

fix: memory leak when calling kong.response.error #133

Closed StarlightIbuki closed 11 months ago

StarlightIbuki commented 1 year ago

It seems the channel is put into a message no matter if a return value is expected here, while here it skips the fetching of the message. A fair guess is that the message is accumulating when we repeatedly call kong.response.error. Fix #59

hanshuebner commented 12 months ago

@fffonion Can you please review this?

fffonion commented 12 months ago

This doesn't seem to be the right fix, as it essentially reverts https://github.com/Kong/kong-python-pdk/commit/ba3d5fae2b040804b1463585641919f76390feda, which fixes https://github.com/Kong/kong-python-pdk/issues/34. I think something else is not freeing up. The channel itself might need a explict free.

StarlightIbuki commented 11 months ago

This doesn't seem to be the right fix, as it essentially reverts ba3d5fa, which fixes #34. I think something else is not freeing up. The channel itself might need a explict free.

I reviewed the changes and found them different, and #34 is also fixed with this patch. I've updated the patch to make it more readable.

The queue is always filled with a tuple even for non_return_methods (in that case, an empty tuple is returned). The fix https://github.com/Kong/kong-python-pdk/commit/ba3d5fae2b040804b1463585641919f76390feda skips the line poping the queue, which causes the leak.

Talked with @fffonion offline. The fix is not correct.