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

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

Closed
embray opened this issue Apr 23, 2019 · 13 comments
Closed

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

embray opened this issue Apr 23, 2019 · 13 comments

Comments

@embray
Copy link
Contributor

embray commented Apr 23, 2019

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

Upstream: Reported upstream. No feedback yet.

Component: notebook

Author: Erik Bray

Branch/Commit: 75bcf77

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/27715

@embray embray added this to the sage-8.8 milestone Apr 23, 2019
@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

comment:1

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.

@embray

This comment has been minimized.

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

Upstream: Reported upstream. No feedback yet.

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

comment:3

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

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

Commit: 75bcf77

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

Branch: u/embray/ticket-27715

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

Author: Erik Bray

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

comment:4

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

@embray
Copy link
Contributor Author

embray commented Apr 23, 2019

comment:5

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

@embray
Copy link
Contributor Author

embray commented Apr 24, 2019

comment:6

Note possible slight conflict with #26919.

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2019

comment:7

LGTM.

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2019

Reviewer: Travis Scrimshaw

@vbraun
Copy link
Member

vbraun commented Apr 29, 2019

Changed branch from u/embray/ticket-27715 to 75bcf77

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

No branches or pull requests

3 participants