Univention Bugzilla – Bug 57104
UMC-Server: memory leaks
Last modified: 2024-03-20 17:18:14 CET
There are memory leaks in the UMC-server: 1. univention.management.console.resource.Resource.get_current_user() assigns a fake translation function for the session, which holds a reference the the Resource/RequestHandler. The RequestHandler is therefore never garbage collected. def get_current_user(self): session = Session.get_or_create(self.get_session_id()) # FIXME: this creates a Session instance even if the session does not exists - session._ = lambda *args: self._(*args) # hack to prevent circular use, when "_" is not yet set but only in prepare() # noqa: PLW0108 + weakself = weakref.ref(self) + session._ = lambda *args: weakself()._(*args) # hack to prevent circular use, when "_" is not yet set but only in prepare() # noqa: PLW0108 if not session.user.ip: session.user.ip = self.get_ip_address() return session 2. univention.management.console.message.Request.get_user_ldap_connection() adds a "self.bind_user_connection" reference to a LDAP connection cache (in .ldap.LDAP.__ldap_connections), which references the Request object, so that this is never garbage collected. def get_user_ldap_connection(self, no_cache=False, **kwargs): if not self.user_dn: return # local user (probably root) + + wheakself = weakref.ref(self) + + def bind_user_connection(lo): + return wheakself().bind_user_connection(lo) + try: - lo, _po = get_user_connection(bind=self.bind_user_connection, write=kwargs.pop('write', False), follow_referral=True, no_cache=no_cache, **kwargs) + lo, _po = get_user_connection(bind=bind_user_connection, write=kwargs.pop('write', False), follow_referral=True, no_cache=no_cache, **kwargs) 3. univention.management.console.session.Session passes "self" to .IACLs and .Processes, which holds them so that a circular reference exists. Note that Session.renew() throws away the IACLs and Processes instances, without e.g. unassigning the .session reference, which will cause that they never get garbage collected.
MR: https://git.knut.univention.de/univention/ucs/-/merge_requests/1079
The memory leaks have been addressed. A additional signal handler SIGUSR2 has been added, which (if python3-objgraph) prints the amount of most used univention.management.console objects into the logfile, so one can compare pre/post states. Additionally the README.md has been adjusted on strategies how to analyze memory leaks. univention-management-console.yaml 61ba40525d8b | fix(umc): fix memory leaks / circular references univention-management-console (12.0.32-21) 61ba40525d8b | fix(umc): fix memory leaks / circular references univention-management-console (12.0.32-20) 5abccd9ecf3a | feat(umc): Add SIGUSR2 signal handler to analyze memory
OK: changelog and YAML OK: logging of memory information using objgraph OK: jenkins tests OK: using the new memory information functionality, various memory leaks are now gone OK: UMC functionality TODO: univention.uldap.access and univention.admin.uldap.access still appear to leak, however this is not new in this bug and will be fixed separately
As discussed, we would like to postpone the release until the other leaks are fixed as well.
reverted and moved into https://git.knut.univention.de/univention/ucs/-/merge_requests/1088.
UCS 5.2: univention-management-console (14.0.6) 931256fbf68a | fix(umc): fix memory leaks / circular references UCS 5.1: univention-management-console (13.0.11) dd95941614c2 | fix(umc): fix memory leaks / circular references UCS 5.0-7: univention-management-console (12.0.33-1) cb6a9ca914d5 | fix(umc): fix memory leaks / circular references
OK: changelog and YAML OK: logging of memory information using objgraph OK: jenkins tests OK: using the new memory information functionality, various memory leaks are now gone OK: UMC functionality OK: using the memory information, no more objects stay behind after session ends
<https://errata.software-univention.de/#/?erratum=5.0x996>