vatlab / sos-notebook

Multi-language Jupyter Notebook
http://vatlab.github.io/SoS
BSD 3-Clause "New" or "Revised" License
177 stars 17 forks source link

SoS Kernel restart fails due to zmq.error.ZMQError: Address already in use #317

Open DavidHuebner opened 3 years ago

DavidHuebner commented 3 years ago

Problem

Restarting a Jupyter Notebook with SoS kernel crashes each time with the following error logs:

Traceback (most recent call last): File "/opt/conda/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/opt/conda/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/opt/conda/lib/python3.9/site-packages/sos_notebook/kernel.py", line 1956, in IPKernelApp.launch_instance(kernel_class=SoS_Kernel) File "/opt/conda/lib/python3.9/site-packages/traitlets/config/application.py", line 844, in launch_instance app.initialize(argv) File "/opt/conda/lib/python3.9/site-packages/traitlets/config/application.py", line 87, in inner return method(app, *args, **kwargs) File "/opt/conda/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 567, in initialize self.init_sockets() File "/opt/conda/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 271, in init_sockets self.shell_port = self._bind_socket(self.shell_socket, self.shell_port) File "/opt/conda/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 218, in _bind_socket return self._try_bind_socket(s, port) File "/opt/conda/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 194, in _try_bind_socket s.bind("tcp://%s:%i" % (self.ip, port)) File "/opt/conda/lib/python3.9/site-packages/zmq/sugar/socket.py", line 172, in bind super().bind(addr) File "zmq/backend/cython/socket.pyx", line 540, in zmq.backend.cython.socket.Socket.bind File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc zmq.error.ZMQError: Address already in use

It tries restarting the kernel for five times, then the SoS Kernel is dead with the following log and screenshot.

Future exception was never retrieved future: <Future finished exception=RuntimeError('Restart failed')> RuntimeError: Restart failed

image

Clicking on "Try Restarting Now" actually work, but this should not be the "appropriate" way to restart the kernel and causes a bad user experience.

Steps to reproduce the error

I created a very simple Dockerfile to reproduce the error.

FROM jupyter/base-notebook

# Install python dependencies
RUN pip3 install sos-notebook==0.22.4
RUN pip3 install sos==0.22.4
RUN python -m sos_notebook.install

USER jovyan
CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]
  1. Put the above content into a Dockerfile
  2. Open a terminal in that directory and execute docker build . -t sos-test
  3. Run the docker container with docker run -p 8888:8888 sos-test
  4. Open the Jupyter Notebook
  5. Create a new Notebook with SoS Kernel
  6. Execute any python command in that notebook, e.g. print("hi")
  7. Restart the kernel
BoPeng commented 3 years ago

This looks scary and might be caused by recent releases of jupyter notebook and/or python. Anyway, the focus of development of the sos notebook project has long been moved to jupyterlab. Is there any reason you cannot use the jupyterlab frontend?

BoPeng commented 3 years ago

I can confirm this bug with the official sos-notebook docker image, and also confirm that the jupyterlab frontend is immune from this problem.

BoPeng commented 3 years ago

I spent a few hours on this issue but could not find a solution. I will have to revisit this issue later.

DavidHuebner commented 3 years ago

This looks scary and might be caused by recent releases of jupyter notebook and/or python. Anyway, the focus of development of the sos notebook project has long been moved to jupyterlab. Is there any reason you cannot use the jupyterlab frontend?

Thanks for your quick reply and investigation. We are developing a custom Jupyter kernel and want to provide a Binder link. The main reason why we are not using the jupyterlab frontend is because we found the integration with Binder to be very difficult, especially when installing the required jupyterlab extensions. We might try that route again.