getdns-python-bindings icon indicating copy to clipboard operation
getdns-python-bindings copied to clipboard

Doing queries leak memory

Open rytilahti opened this issue 8 years ago • 2 comments

Some structures allocated by the binding are not being freed/dereffed correctly. A simple testcase:

import resource import getdns

resolver = getdns.Context()

for i in range(10000): extensions = {"return_both_v4_and_v6": getdns.EXTENSION_TRUE} res = resolver.address(name="google.com", extensions=extensions) if i % 100 == 0: print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)

$ pip3 list|grep getdns getdns (1.0b0)

rytilahti avatar Aug 01 '16 15:08 rytilahti

By way of an update, I've isolated this to the result object and am continuing to look into it.

MelindaShore avatar Sep 06 '16 20:09 MelindaShore

I am facing the same issue. I am performing DNS lookup inside a flask app. So with each request, the memory usage keeps on increasing. The memory gets freed only after the app is restarted/stopped.

A sample code:

import getdns
from flask import Flask, jsonify

app = Flask(__name__)


@app.route('/address')
def get_address():
    name = 'google.com'

    extensions = {"return_both_v4_and_v6": getdns.EXTENSION_TRUE}
    
    ctx = getdns.Context()
    response = ctx.address(name, extensions=extensions)

    return jsonify(data=response.just_address_answers)


if __name__ == '__main__':
    app.run()

Am I missing something? Is there any way to destroy the result object on request completion?

Autopilot9369 avatar Sep 23 '19 05:09 Autopilot9369