Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak of IOLoopKernelManager object #361

Merged
merged 1 commit into from
Mar 22, 2018

Conversation

kevin-bates
Copy link
Member

After analyzing various leaked items when running either Notebook or
Jupyter Kernel Gateway, one item that recurred across each kernel
startup and shutdown sequence was an instance of IOLoopKernelManager.
(Of course, when using JKG, this instance was KernelGatewayIOLoopKernelManager
since it derives from the former.)

The leak is caused by the circular references established in the self._restarter
and self.session.parent members. This change breaks the circular reference when
the restarter is stopped and during cleanup() of the kernel manager. Once the
references are broken, the kernel manager instance can be garbage collected.

After analyzing various leaked items when running either Notebook or
Jupyter Kernel Gateway, one item that recurred across each kernel
startup and shutdown sequence was an instance of IOLoopKernelManager.
(Of course, when using JKG, this instance was KernelGatewayIOLoopKernelManager
since it derives from the former.)

The leak is caused by the circular references established in the `self._restarter`
and `self.session.parent` members. This change breaks the circular reference when
the restarter is stopped and during `cleanup()` of the kernel manager.  Once the
references are broken, the kernel manager instance can be garbage collected.
kevin-bates added a commit to kevin-bates/enterprise_gateway that referenced this pull request Mar 14, 2018
PR jupyter-server#279 introduced some fixes to address file descriptor leaks - one of
which was to shutdown the communication port.  Since the kernel launcher
listening on the other side may have already terminated, the shutdown
method could throw an exception.  This change catches, logs, then ignores
such exceptions.

While looking into other leaks (in this case memory), it was discovered
that the process proxy instance was being leaked across kernel cycles.
This change addresses that particular leak.

Note: Other PRs have also been submitted to address leaks in
`jupyter_client` and `notebook`.  These are:

[PR 360 - Fix memory leak of kernel Popen object](jupyter/jupyter_client#360)
[PR 361 - Fix memory leak of IOLoopKernelManager object](jupyter/jupyter_client#361)
[PR 3424 - Fix memory leak of iopub object in activity monitoring](jupyter/notebook#3424)
lresende pushed a commit to jupyter-server/enterprise_gateway that referenced this pull request Mar 19, 2018
While looking into other leaks (in this case memory), it was discovered
that the process proxy instance was being leaked across kernel cycles.
This change addresses that particular leak.

Note: Other PRs have also been submitted to address leaks in
`jupyter_client` and `notebook`.  These are:

[PR 360 - Fix memory leak of kernel Popen object](jupyter/jupyter_client#360)
[PR 361 - Fix memory leak of IOLoopKernelManager object](jupyter/jupyter_client#361)
[PR 3424 - Fix memory leak of iopub object in activity monitoring](jupyter/notebook#3424)
@minrk minrk merged commit 8f62a36 into jupyter:master Mar 22, 2018
@kevin-bates
Copy link
Member Author

@minrk - thank you for merging these PRs. Can we assume that 5.2.4 will be released in a couple weeks given the other 5.2.x releases have been about 3-4 weeks apart?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants