Opened 2 years ago

Closed 2 years ago

#27715 closed defect (fixed)

Jupyter notebook can crash during startup if default port cannot be used

Reported by: embray Owned by:
Priority: major Milestone: sage-8.8
Component: notebook Keywords:
Cc: Merged in:
Authors: Erik Bray Reviewers: Travis Scrimshaw
Report Upstream: Reported upstream. No feedback yet. Work issues:
Branch: 75bcf77 (Commits, GitHub, GitLab) Commit: 75bcf7789bed4dca62c7d110fa4e470aaedcc3c5
Dependencies: Stopgaps:

Status badges

Description (last modified by embray)

Per reports like this one, it seems there is some condition (I am not sure yet what) such that on Windows trying to bind to port 8888 results in a permission error, on which the notebook crashes:

[I 17:51:21.659 NotebookApp] Using MathJax: nbextensions/mathjax/MathJax.js Traceback (most recent call last):

File "/opt/sagemath-8.6/src/bin/sage-notebook", line 268, in <module> launcher(unknown)

File "/opt/sagemath-8.6/src/bin/sage-notebook", line 100, in __init__ main(argv)

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance app.initialize(argv)

File "<decorator-gen-7>", line 2, in initialize
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error return method(app, args, *kwargs)

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1629, in initialize self.init_webapp()

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1408, in init_webapp self.http_server.listen(port, self.ip)

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/tornado/tcpserver.py", line 142, in listen sockets = bind_sockets(port, address=address)

File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/tornado/netutil.py", line 197, in bind_sockets sock.bind(sockaddr)
File "/opt/sagemath-8.6/local/lib/python2.7/socket.py", line 230, in meth return getattr(self._sock,name)(*args)

socket.error: [Errno 1] Operation not permitted

The notebook already has some code to try other ports if the requested port fails:

        for port in random_ports(self.port, self.port_retries+1):
            try:
                self.http_server.listen(port, self.ip)
            except socket.error as e:
                if e.errno == errno.EADDRINUSE:
                    self.log.info(_('The port %i is already in use, trying another port.') % port)
                    continue
                elif e.errno in (errno.EACCES, getattr(errno, 'WSAEACCES', errno.EACCES)):
                    self.log.warning(_("Permission to listen on port %i denied") % port)
                    continue
                else:
                    raise

However, in this case some reason users are getting EPERM instead of EACCES and that case is not handled in the above code.

Upstream PR: https://github.com/jupyter/notebook/pull/4584/files

Change History (8)

comment:1 Changed 2 years ago by embray

As it happens, the POSIX specification for bind() does not mention EPERM as an expected error, just EACCES. Perhaps this is a Cygwin-specific bug. Will have to dig a bit to see where it might be coming from.

comment:2 Changed 2 years ago by embray

  • Description modified (diff)
  • Report Upstream changed from N/A to Reported upstream. No feedback yet.

comment:3 Changed 2 years ago by embray

I confirmed that this is likely a bug in Cygwin. For now though it is easiest to workaround in the Notebook code.

comment:4 Changed 2 years ago by embray

  • Authors set to Erik Bray
  • Branch set to u/embray/ticket-27715
  • Commit set to 75bcf7789bed4dca62c7d110fa4e470aaedcc3c5
  • Status changed from new to needs_review

I'm okay, in this case, with just patching the package in Sage, since the patch is only needed (in some cases) on Cygwin, so it won't be needed by most other downstream packagers, etc.

I will just note for the record that the issue could be worked around by monkey-patching, but this is probably easier in this case.


New commits:

75bcf77Ticket #27715: Add upstream patch to fix notebook socket permission

comment:5 Changed 2 years ago by embray

I will also probably backport this to Sage 8.7 for Windows now that I have a mechanism for that.

comment:6 Changed 2 years ago by embray

Note possible slight conflict with #26919.

comment:7 Changed 2 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM.

comment:8 Changed 2 years ago by vbraun

  • Branch changed from u/embray/ticket-27715 to 75bcf7789bed4dca62c7d110fa4e470aaedcc3c5
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.