microsoft / vscode-jupyter

VS Code Jupyter extension

Home Page:https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot run cell: freezes indefinitely (WSL, Docker, mamba)

aaronshenhao opened this issue · comments

Environment data

  • VS Code version: 1.89.0
  • Jupyter Extension version (available under the Extensions sidebar): v2024.4.0
  • Python Extension version (available under the Extensions sidebar): v2024.6.0
  • OS (Windows | Mac | Linux distro) and version: Microsoft Windows 11 Home Version 10.0.22631 Build 22631
  • Python and/or Anaconda version: Python 3.12.3, mamba 1.4.2, conda 23.3.1
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Mamba running on Docker
  • Jupyter server running: Remote

Expected behaviour

Clicking run on a cell should run it, and the execution should complete in a reasonable time.

Actual behaviour

The cell runs indefinitely, or outputs the following error message:

Failed to connect to the remote Jupyter Server 'http://127.0.0.1:8888/'. Verify the server is running and reachable. ('_xsrf' argument missing from POST).

Jupyter Lab's web-based notebook works normally. The issue only affects VS Code.

Steps to reproduce:

  1. Setup the environment by creating the mamba image using the mamba dockerfile, then run docker compose up in the project directory. The container should bind to the current directory and set up a Jupyter Lab server at http://127.0.0.1:8888.

Mamba Dockerfile

FROM ubuntu:jammy

WORKDIR /workspace

RUN apt-get update && \
    apt-get install aria2 curl git -y && \
    curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" && \
    bash Miniforge3-$(uname)-$(uname -m).sh -bfp /opt/miniforge3 && \
    rm Miniforge3-$(uname)-$(uname -m).sh

# Not really necessary
ENV PATH=/opt/miniforge3/bin:$PATH
RUN mamba init

Dockerfile

FROM mamba

WORKDIR /app

COPY environment.yml .
RUN mamba env create -f environment.yml

docker-compose.yaml

services:
  jupyter:
    build: .
    ports:
      - 8888:8888
    volumes:
      - .:/app # Bind mount, changes will be reflected in host
    command:
      [
        "mamba",
        "run",
        "--no-capture-output", # For mamba/conda to show output
        "-n",
        "real-estate",
        "jupyter",
        "lab",
        "--ip=0.0.0.0", # So it listens on all interfaces, not just localhost
        "--port=8888",
        "--allow-root", # To allow running as root (prevent permission errors)
        "--NotebookApp.token=''", # To prevent Jupiter lab asking for tokens
        "--NotebookApp.password=''"
      ]

environment.yml

name: real-estate
channels:
  - conda-forge
dependencies:
  - folium
  - geopandas
  - jupyterlab
  1. Create a new .ipynb file with a single cell: print("Hello world")

  2. Run the cell. When asked to select a kernal, select "Existing Jupyter Server" and use http://127.0.0.1:8888 as the remote server, then select the recommended kernal (should be in /opt/miniforge3/envs/real-estate/bin...).

Other details:

  • The host machine should not have git, python, mamba or jupyter installed.
  • Verify that it works as expected when accessed through the browser.
  • Code was contained in WSL 2 (Ubuntu) partition.
    • Version: Ubuntu 22.04.4 LTS
  • Using Docker on Windows with WSL2 backend.

Logs

Output for Jupyter Lab running on Docker (on run)

2024-05-04 18:29:11 [W 2024-05-04 08:29:11.453 ServerApp] 404 GET /hub/api (20ee2cc48e734e938d4dcd892794b5ed@172.18.0.1) 1.60ms referer=None
2024-05-04 18:29:11 [W 2024-05-04 08:29:11.493 ServerApp] 403 POST /api/sessions?1714811351491 (172.18.0.1): '_xsrf' argument missing from POST
2024-05-04 18:29:11 [W 2024-05-04 08:29:11.494 ServerApp] wrote error: "'_xsrf' argument missing from POST"
2024-05-04 18:29:11     Traceback (most recent call last):
2024-05-04 18:29:11       File "/opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/tornado/web.py", line 1769, in _execute
2024-05-04 18:29:11         result = await result  # type: ignore
2024-05-04 18:29:11                  ^^^^^^^^^^^^
2024-05-04 18:29:11       File "/opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/jupyter_server/base/handlers.py", line 751, in prepare
2024-05-04 18:29:11         await super().prepare()
2024-05-04 18:29:11       File "/opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/jupyter_server/base/handlers.py", line 633, in prepare
2024-05-04 18:29:11         self.check_xsrf_cookie()
2024-05-04 18:29:11       File "/opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/jupyter_server/base/handlers.py", line 537, in check_xsrf_cookie
2024-05-04 18:29:11         return super().check_xsrf_cookie()
2024-05-04 18:29:11                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-04 18:29:11       File "/opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/tornado/web.py", line 1605, in check_xsrf_cookie
2024-05-04 18:29:11         raise HTTPError(403, "'_xsrf' argument missing from POST")
2024-05-04 18:29:11     tornado.web.HTTPError: HTTP 403: Forbidden ('_xsrf' argument missing from POST)
2024-05-04 18:29:11 [W 2024-05-04 08:29:11.494 ServerApp] 403 POST /api/sessions?1714811351491 (bd88f50f8f00404d93c04f4294491d73@172.18.0.1) 1.29ms referer=None

Output for Jupyter Lab running on Docker (on initialization)

2024-05-04 16:39:51 [I 2024-05-04 06:39:51.601 ServerApp] jupyter_lsp | extension was successfully linked.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.604 ServerApp] jupyter_server_terminals | extension was successfully linked.
2024-05-04 16:39:51 [W 2024-05-04 06:39:51.607 LabApp] 'token' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
2024-05-04 16:39:51 [W 2024-05-04 06:39:51.607 LabApp] 'password' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
2024-05-04 16:39:51 [W 2024-05-04 06:39:51.611 ServerApp] ServerApp.token config is deprecated in 2.0. Use IdentityProvider.token.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.611 ServerApp] jupyterlab | extension was successfully linked.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.612 ServerApp] Writing Jupyter server cookie secret to /root/.local/share/jupyter/runtime/jupyter_cookie_secret
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.777 ServerApp] notebook_shim | extension was successfully linked.
2024-05-04 16:39:51 [W 2024-05-04 06:39:51.789 ServerApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.790 ServerApp] notebook_shim | extension was successfully loaded.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.791 ServerApp] jupyter_lsp | extension was successfully loaded.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.792 ServerApp] jupyter_server_terminals | extension was successfully loaded.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.793 LabApp] JupyterLab extension loaded from /opt/miniforge3/envs/real-estate/lib/python3.12/site-packages/jupyterlab
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.793 LabApp] JupyterLab application directory is /opt/miniforge3/envs/real-estate/share/jupyter/lab
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.794 LabApp] Extension Manager is 'pypi'.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.804 ServerApp] jupyterlab | extension was successfully loaded.
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.804 ServerApp] Serving notebooks from local directory: /app
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.805 ServerApp] Jupyter Server 2.14.0 is running at:
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.805 ServerApp] http://0f6e871f0450:8888/lab
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.805 ServerApp]     http://127.0.0.1:8888/lab
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.805 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2024-05-04 16:39:51 [W 2024-05-04 06:39:51.808 ServerApp] No web browser found: Error('could not locate runnable browser').
2024-05-04 16:39:51 [I 2024-05-04 06:39:51.822 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
2024-05-04 16:39:55 [I 2024-05-04 06:39:55.678 ServerApp] 302 GET / (@172.18.0.1) 0.77ms
2024-05-04 16:39:56 [W 2024-05-04 06:39:56.596 LabApp] Could not determine jupyterlab build status without nodejs