danielballan / jupyterhub-share-link

Share notebooks between users in a Hub.
Other
24 stars 3 forks source link

Cannot assign requested address(or tornado.iostream.StreamClosedError: Stream is closed) #5

Open RAbraham opened 4 years ago

RAbraham commented 4 years ago

Hi, I'm testing this locally. I generated a url and when putting the url in the browser for another user, I get a 500 error. Inspecting the logs, I see

jhub   | [I 200214 04:12:24 run:108] Honoring token {'user': 'rabraham', 'path': 'Untitled1.ipynb', 'opts': {'image': 'localhost:5000/base-notebook-with-jupyterhub-share-labextension'}, 'exp': 1581657129}
jhub   | [I 2020-02-14 04:12:24.167 JupyterHub log:174] 200 GET /hub/api/users/rabraham (share-link@172.20.0.2) 19.66ms
jhub   | [I 2020-02-14 04:12:24.266 JupyterHub log:174] 200 GET /hub/api/users/rabraham (share-link@172.20.0.2) 24.02ms
jhub   | [I 2020-02-14 04:12:24.324 JupyterHub log:174] 200 GET /hub/api/users/rabraham_r (share-link@172.20.0.2) 30.37ms
jhub   | [E 200214 04:12:24 web:1788] Uncaught exception GET /services/share-link/open?token=ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKU1V6STFOaUo5LmV5SjFjMlZ5SWpvaWNtRmljbUZvWVcwaUxDSndZWFJvSWpvaVZXNTBhWFJzWldReExtbHdlVzVpSWl3aWIzQjBjeUk2ZXlKcGJXRm5aU0k2SW14dlkyRnNhRzl6ZERvMU1EQXdMMkpoYzJVdGJtOTBaV0p2YjJzdGQybDBhQzFxZFhCNWRHVnlhSFZpTFhOb1lYSmxMV3hoWW1WNGRHVnVjMmx2YmlKOUxDSmxlSEFpT2pFMU9ERTJOVGN4TWpsOS5KemF5Y3RPNFE3OWo4VXFjbGJNTWh1SERvUXVYYjl1d0YyNUVVMWhQWmJOTDZ2dTFQMko3R0JlZ09TNzcwZUt1V2lZa0JwelBLTy15YkJzc2QyN0ZEMmpBc1hZTk00NDhxOHA1c050VHg0ZERPNGJON3ZHNTNHb2dJWUdIdV9jcmpIZzRTUEpyZW9pcWxqc2tOSHJ4VU1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Rjbi1iWTRPalZEZHp2ZUVLWm9CNGdHV2tzaHR3R2hoUFNUdmtPMnc=', version='HTTP/1.1', remote_ip='127.0.0.1')
jhub   |     Traceback (most recent call last):
jhub   |       File "/usr/local/lib/python3.6/dist-packages/tornado/tcpclient.py", line 143, in on_connect_done
jhub   |         stream = future.result()
jhub   |     tornado.iostream.StreamClosedError: Stream is closed
jhub   |
jhub   |     During handling of the above exception, another exception occurred:
jhub   |
jhub   |     Traceback (most recent call last):
jhub   |       File "/usr/local/lib/python3.6/dist-packages/tornado/web.py", line 1699, in _execute
jhub   |         result = await result
jhub   |       File "/usr/local/lib/python3.6/dist-packages/jupyterhub_share_link/run.py", line 195, in get
jhub   |         resp = await AsyncHTTPClient().fetch(req)
jhub   |       File "/usr/local/lib/python3.6/dist-packages/tornado/iostream.py", line 1200, in connect
jhub   |         self.socket.connect(address)
jhub   |     OSError: [Errno 99] Cannot assign requested address

On a side note, as user2(the person who user1 gives the link too) , I have to login and spawn my notebook server before I can paste the url in the browser.

RAbraham commented 4 years ago

This is my jupyterhub_config.py. The one thing I'm not sure about in my config wrt the example_container_config is

c.JupyterHub.hub_ip = public_ips()[0]

I have

c.JupyterHub.hub_ip = 'jhub'

as I saw that somewhere in a perhaps a docker-compose tutorial and my installation works like that but I'm not sure if that is the reason why it fails here?

import dockerspawner
from traitlets.config import get_config
import sys
import os
c = get_config()
os.environ['OAUTH2_TOKEN_URL']= f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/token"
from oauthenticator.generic import GenericOAuthenticator
c.JupyterHub.authenticator_class = GenericOAuthenticator

c.JupyterHub.authenticator_class.login_handler._OAUTH_AUTHORIZE_URL=f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/auth"

c.OAuthenticator.login_service = "15Rock"
c.OAuthenticator.client_id = os.environ['CLIENT_ID']
c.OAuthenticator.client_secret = os.environ['CLIENT_SECRET']
c.OAuthenticator.token_url = f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/token"
c.OAuthenticator.userdata_url = f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/userinfo"
c.OAuthenticator.userdata_method = 'GET'
c.OAuthenticator.userdata_params = {"state": "state"}
c.OAuthenticator.username_key = "preferred_username"

os.environ['OAUTH2_AUTHORIZE_URL']= f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/auth"
os.environ['OAUTH2_TOKEN_URL']= f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/token"
os.environ['OAUTH_CALLBACK_URL']= f"{os.environ['NOTEBOOK_URL']}/hub/oauth_callback"
os.environ['OAUTH2_USERDATA_URL']= f"{os.environ['HOST_URL']}/auth/realms/master/protocol/openid-connect/userinfo"
c.Spawner.args = [f"--NotebookApp.tornado_settings={{\"headers\":{{\"Content-Security-Policy\": \"frame-ancestors 'self' {os.environ['HOST_URL']}\"}}}}"]
c.JupyterHub.tornado_settings = {
  'headers': {
    'Content-Security-Policy': f"frame-ancestors 'self' {os.environ['HOST_URL']}"
  }
}

#c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
#c.DummyAuthenticator.password = "jam"
c.JupyterHub.cookie_secret = b'mysecret'

c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
spawn_cmd = os.environ.get('DOCKER_SPAWN_CMD', "start-singleuser.sh")
c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd })

c.DockerSpawner.debug = True

notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'

c.DockerSpawner.notebook_dir = notebook_dir
c.DockerSpawner.image = os.environ['DOCKER_JUPYTER_CONTAINER']

c.DockerSpawner.http_timeout=600
c.DockerSpawner.start_timeout=1200
# Mount the real user's Docker volume on the host to the notebook user's
# notebook directory in the container

c.DockerSpawner.volumes = { 'jupyterhub-user-{username}': notebook_dir }

## Docker spawner

network_name = os.environ['DOCKER_NETWORK_NAME']
c.DockerSpawner.network_name = network_name
c.DockerSpawner.use_internal_ip = True

c.JupyterHub.hub_ip = 'jhub'

c.JupyterHub.services = [
    {
        'name': 'share-link',
        'admin': True,
        'url': 'http://127.0.0.1:21211',
        'command': [sys.executable, '-m', 'jupyterhub_share_link.run'],
    },
    {
        # the /services/<name> path for accessing the notebook viewer
        'name': 'nbviewer',
        # the interface and port nbviewer will use
        'url': 'http://127.0.0.1:9000',
         # the path to nbviewer repo
        'cwd': '/srv/jupyterhub/nbviewer',
        # command to start the nbviewer
        'command': [sys.executable, '-m', 'nbviewer']
    }

]
c.JupyterHub.admin_access = True  # Service needs to access user servers.

c.JupyterHub.allow_named_servers = True
c.Spawner.cmd = ['jupyter-labhub']

c.DockerSpawner.remove_containers = True
c.DockerSpawner.image_whitelist = [
    'localhost:5000/base-notebook-with-jupyterhub-share-labextension',
    'danielballan/scipy-notebook-with-jupyterhub-share-labextension',
]

c.DockerSpawner.name_template = "{prefix}-{username}-{servername}"

c.Spawner.default_url = '/lab'