From: Martin <md...@md...> - 2003-01-08 18:42:23
|
ons 2003-01-08 klockan 12.24 skrev Zoltan Felleg: > this method for me results in constantly growing memory usage of the=20 > server (about 10-20MB per minute). and the id of the Connection object=20 > is constantly changing (growing), while the Context remains the same (as=20 > expected), so i'm assuming the Connection objects returned by the accept=20 > method do not get deleted. (i tied to explicitly delete both the=20 > connection object and its context, but the leak remained). Hmm, I guess I'll have to monitor it a bit longer. > the script i was using follows: I think I've figured out the problem. > class client: > def __init__(self): > self.ctx =3D OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD) > self.ctx.set_verify(OpenSSL.SSL.VERIFY_PEER, self.verifycb) Using self.verifycb introduces a cyclic reference. > self.ctx.use_privatekey_file(client_kf) > self.ctx.use_certificate_file(client_cf) > self.ctx.load_verify_locations(ca_cf) > sock =3D socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self.co =3D OpenSSL.tsafe.Connection(self.ctx, sock) The use of self.ctx here is also cyclic. > def verifycb(self, conn, cert, errnum, depth, ok): > return ok >=20 >=20 > if __name__ =3D=3D '__main__': > time.sleep(5) > for i in range(10000): > print i > clt =3D client() > clt.co.close() > del clt.ctx > del clt.co > time.sleep(10) >=20 > when both the del clt.ctx and del clt.co lines are there, there is no=20 > leak at all. if both of them are commented out, the memory usage goes to=20 > about 100MB, and if only the context is deleted, the memory usage is=20 > about 80MB. Add a def __del__(self): print 'del' method and you'll see that when both the del:s in the loop are present, it'll print 'del', but if you comment any one of them they will disappear. Compare with a similar program. =3D=3D=3D class foo: def __init__(self, x): self.foo =3D x class bar: def __init__(self): self.bar =3D foo(self.m) def m(self): pass def __del__(self): print 'del' while 1: x =3D bar() #del x.bar =3D=3D=3D It has the exact same problem. /Martin |