jupyter-matlab-proxy icon indicating copy to clipboard operation
jupyter-matlab-proxy copied to clipboard

MATLAB kernel could not communicate with MATLAB in JupyterLab through JupyterHub (with reverse proxy nginx)

Open ytdHuang opened this issue 10 months ago • 8 comments

Hi, I'm using JupyterLab through JupyterHub (with reverse proxy nginx)

All the users can login to JupyterHub and do matlab calculations through terminal

> matlab
MATLAB is selecting SOFTWARE OPENGL rendering.

                                < M A T L A B (R) >
                      Copyright 1984-2021 The MathWorks, Inc.
                     R2021b (9.11.0.1769968) 64-bit (glnxa64)
                                September 17, 2021

 
To get started, type doc.
For product information, visit www.mathworks.com.
 
>> 1+1

ans =

     2

>> 

When I open matlab from the Launcher in JupyterLab (notebook or console), the status of the kernel will show Idle, but if I type 1+1, it pops out an error:

Error: MATLAB Kernel could not communicate with MATLAB.
Reason: Possibly due to invalid jupyter security tokens.

The version of matlab, python and related packages:

  • matlab==R2021b
  • Python==3.8.8
  • JupyterHub==3.1.1
  • JupyterLab==4.0.5
  • jupyter-matlab-proxy==0.11.0

Does anyone know how to fix the invalid jupyter security tokens, or did I miss any settings ?

ytdHuang avatar Apr 24 '24 06:04 ytdHuang

Dear @ytdHuang

This should be fixed by the latest versions of matlab-proxy and jupyter-matlab-proxy.

Could you please upgrade these packages using the command :

python3 -m pip install --upgrade jupyter-matlab-proxy matlab-proxy

Please let us know if the upgraded packages resolves this issue.

prabhakk-mw avatar May 10 '24 13:05 prabhakk-mw

Fixed by https://github.com/mathworks/matlab-proxy/commit/c8808f451b8aab76ba03936b7ce877c8dbcacc89

prabhakk-mw avatar May 10 '24 13:05 prabhakk-mw

Seems that the error still exists

ytdHuang avatar May 10 '24 14:05 ytdHuang

@ytdHuang Could you please share the results of running troubleshooting.py from a terminal from within your Jupyter environment?

prabhakk-mw avatar May 10 '24 14:05 prabhakk-mw

My guess is that it probably didn't work for you as you would have to make these upgrades at the JupyterHub level so that it is already in effect when the notebook server is created at the time of login.

prabhakk-mw avatar May 10 '24 14:05 prabhakk-mw

@prabhakk-mw

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                            MATLAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------

matlab - /usr/local/bin/matlab OK

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                       matlab-proxy-app
--------------------------------------------------------------------------------------------------------------------------------------------------------------

matlab-proxy-app - /usr/local/anaconda3/envs/JServer/bin/matlab-proxy-app OK

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                           Jupyter
--------------------------------------------------------------------------------------------------------------------------------------------------------------

jupyter - /usr/local/anaconda3/envs/JServer/bin/jupyter OK

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                  Python and pip executables
--------------------------------------------------------------------------------------------------------------------------------------------------------------

python - /usr/local/anaconda3/envs/JServer/bin/python OK

Python 3.8.8

pip - /usr/local/anaconda3/envs/JServer/bin/pip OK

pip 21.1.1 from /usr/local/anaconda3/envs/JServer/lib/python3.8/site-packages/pip (python 3.8)

python3 - /usr/local/anaconda3/envs/JServer/bin/python3 OK

Python 3.8.8

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                             Xvfb
--------------------------------------------------------------------------------------------------------------------------------------------------------------

Xvfb - /usr/bin/Xvfb OK

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                        OS information
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux
4.18.0-240.1.1.el8_3.x86_64
Linux-4.18.0-240.1.1.el8_3.x86_64-x86_64-with-glibc2.10
uname_result(system='Linux', node='QFort2', release='4.18.0-240.1.1.el8_3.x86_64', version='#1 SMP Thu Nov 19 17:20:08 UTC 2020', machine='x86_64', processor='x86_64')


--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                      Conda information
--------------------------------------------------------------------------------------------------------------------------------------------------------------

conda - /usr/local/anaconda3/condabin/conda

conda 4.10.1

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                      Installed packages
--------------------------------------------------------------------------------------------------------------------------------------------------------------

jupyter-bokeh                     2.0.4
jupyter-client                    8.3.0
jupyter-core                      5.3.1
jupyter-events                    0.7.0
jupyter-lsp                       2.2.0
jupyter-matlab-proxy              0.12.2
jupyter-packaging                 0.9.2
jupyter-resource-usage            1.0.1
jupyter-server                    2.7.2
jupyter-server-fileid             0.9.0
jupyter-server-proxy              3.1.0
jupyter-server-terminals          0.4.4
jupyter-server-ydoc               0.8.0
jupyter-telemetry                 0.1.0
jupyter-ydoc                      0.2.5
jupyterhub                        3.1.1
jupyterhub-systemdspawner         0.16
jupyterlab                        4.0.5
jupyterlab-drawio                 0.9.0
jupyterlab-lsp                    3.10.1
jupyterlab-notify                 2.0.0
jupyterlab-pygments               0.1.2
jupyterlab-server                 2.24.0
jupyterlab-spreadsheet-editor     0.5.1
jupyterlab-topbar                 0.6.1
jupyterlab-widgets                3.0.8
lckr-jupyterlab-variableinspector 3.0.9
matlab-proxy                      0.16.0
notebook                          7.0.2
notebook-shim                     0.2.2

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                  Jupyter server extensions
--------------------------------------------------------------------------------------------------------------------------------------------------------------

Config dir: /root/.jupyter

Config dir: /usr/local/anaconda3/envs/JServer/etc/jupyter
    jupyter_lsp enabled
    - Validating jupyter_lsp...
Package jupyter_lsp took 0.0071s to import
A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
      jupyter_lsp 2.2.0 OK
    jupyter_server_proxy enabled
    - Validating jupyter_server_proxy...
Package jupyter_server_proxy took 0.1138s to import
      jupyter_server_proxy  OK
    jupyter_resource_usage enabled
    - Validating jupyter_resource_usage...
Package jupyter_resource_usage took 0.0088s to import
      jupyter_resource_usage 1.0.1 OK
    jupyter_server_fileid enabled
    - Validating jupyter_server_fileid...
Package jupyter_server_fileid took 0.0019s to import
      jupyter_server_fileid 0.9.0 OK
    jupyter_server_terminals enabled
    - Validating jupyter_server_terminals...
Package jupyter_server_terminals took 0.0031s to import
      jupyter_server_terminals 0.4.4 OK
    jupyter_server_ydoc enabled
    - Validating jupyter_server_ydoc...
Package jupyter_server_ydoc took 0.0140s to import
      jupyter_server_ydoc 0.8.0 OK
    jupyterlab enabled
    - Validating jupyterlab...
Package jupyterlab took 0.0367s to import
      jupyterlab 4.0.5 OK
    jupyterlab_notify enabled
    - Validating jupyterlab_notify...
Package jupyterlab_notify took 0.1764s to import
      jupyterlab_notify 2.0.0 OK
    nbclassic enabled
    - Validating nbclassic...
Package nbclassic took 0.0010s to import
A `_jupyter_server_extension_points` function was not found in nbclassic. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
      nbclassic 0.4.3 OK
    notebook enabled
    - Validating notebook...
Package notebook took 0.0000s to import
       X validation failed
    notebook_shim enabled
    - Validating notebook_shim...
Package notebook_shim took 0.0000s to import
A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
      notebook_shim  OK

Config dir: /usr/local/etc/jupyter

JupyterLab v4.0.5
/usr/local/anaconda3/envs/JServer/share/jupyter/labextensions
        jupyterlab-topbar-extension v0.6.1 enabled  X (python, jupyterlab-topbar)
        spreadsheet-editor v0.5.1 enabled  X (python, jupyterlab-spreadsheet-editor)
        jupyterlab-drawio v0.9.0 enabled  X (python, jupyterlab-drawio)
        JLDracula v0.1.0 enabled  X (python, JLDracula)
        jupyterlab-notify v2.0.0 enabled OK (python, jupyterlab_notify)
        jupyter-matplotlib v0.11.3 enabled OK
        jupyter_matlab_labextension v0.1.0 enabled  X (python, jupyter_matlab_labextension)
        @jupyter-widgets/jupyterlab-manager v5.0.8 enabled OK (python, jupyterlab_widgets)
        @jupyter-server/resource-usage v1.0.1 enabled OK (python, jupyter-resource-usage)
        @lckr/jupyterlab_variableinspector v3.0.9 enabled  X (python, lckr_jupyterlab_variableinspector)
        @aquirdturtle/collapsible_headings v3.1.0 enabled  X (python, aquirdturtle_collapsible_headings)
        @jupyterlab/server-proxy v3.1.0 disabled  X
        @jlab-enhanced/cell-toolbar v3.5.0 enabled  X (python, jlab-enhanced-cell-toolbar)
        @krassowski/jupyterlab-lsp v3.10.1 enabled OK (python, jupyterlab-lsp)
        @jupyter-notebook/lab-extension v7.0.2 enabled OK


   The following extensions are outdated:
        jupyterlab-topbar-extension
        spreadsheet-editor
        jupyterlab-drawio
        JLDracula
        jupyter_matlab_labextension
        @lckr/jupyterlab_variableinspector
        @aquirdturtle/collapsible_headings
        @jupyterlab/server-proxy
        @jlab-enhanced/cell-toolbar

   Consider checking if an update is available for these packages.

Other labextensions (built into JupyterLab)
   app dir: /usr/local/anaconda3/envs/JServer/share/jupyter/lab


Disabled extensions:
    @jupyterlab/server-proxy (all plugins)

The following source extensions are overshadowed by older prebuilt extensions:
    @jupyterlab/server-proxy

--------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                    Environment variables
--------------------------------------------------------------------------------------------------------------------------------------------------------------

ytdHuang avatar May 10 '24 15:05 ytdHuang

@ytdHuang Could you please confirm that the issue remains even after restarting the Jupyter notebook server? When you restart the server are you seeing the upgraded packages being listed by: python -m pip list | grep matlab

prabhakk-mw avatar May 10 '24 16:05 prabhakk-mw

@prabhakk-mw I'm using jupyterlab and I have restarted it after update those packages. However, the issue still exists. Here is the version info. for those packages in my environment now:

  • jupyter-matlab-proxy==0.12.2
  • matlab-proxy==0.16.0

ytdHuang avatar May 11 '24 13:05 ytdHuang

That is odd.

I've verified that the packages themselves work with NGINX reverse proxy using the following docker-compose file:

# Copyright 2024 The MathWorks, Inc.

version: '3'
name: proxied-matlab-container

services:
  proxy:
    image: ubuntu/squid:5.2-22.04_beta
    container_name: squid-container
    networks:
      - isolated
      - external
    ## Uncomment if you want to use a local squid configuration
    # volumes:
    #   - ./squid.conf:/etc/squid/squid.conf
    links:
      - matlab
    restart: always

  matlab:
    image: ghcr.io/mathworks-ref-arch/matlab-integration-for-jupyter/jupyter-matlab-notebook:r2024a
    container_name: jupyter-matlab-container
    tty: true
    # expose only serves as documentation and 
    #  doesn't actually expose these ports outside of this network.
    expose:
      - 8888
    networks:
      - isolated

    environment:
      https_proxy: http://proxy:3128
      http_proxy: http://proxy:3128
      HTTPS_PROXY: http://proxy:3128
      HTTP_PROXY: http://proxy:3128
      MW_PROXY_HOST: proxy
      MW_PROXY_PORT: 3128
      no_proxy: "localhost, 0.0.0.0"
      VIRTUAL_HOST: "127.0.0.1"
      VIRTUAL_PORT: "8888"
      TRUST_DOWNSTREAM_PROXY: "true"
      # See here for VIRTUAL_PORT and VIRTUAL_HOST
      # https://github.com/nginx-proxy/nginx-proxy/tree/main/docs#virtual-ports

  reverse-proxy:
    image: nginxproxy/nginx-proxy:1.5
    container_name: nginx-proxy
    networks:
      - isolated
      - external
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    environment:
      - HTTP_PORT=8888
    ports:
      - "8888:8888"

networks:
  isolated:
    driver: bridge
    internal: true
  external:
    driver: bridge

Test this file by:

  1. Saving this file as compose.yaml onto your machine.
  2. Run docker compose up from the directory in which the file exists
  3. The logs on terminal from jupyter-matlab-container will print out the access link to the Jupyter notebook. It would look something like this:
    jupyter-matlab-container  | [I 2024-05-16 14:24:23.946 ServerApp] Serving notebooks from local directory: /home/jovyan
    jupyter-matlab-container  | [I 2024-05-16 14:24:23.946 ServerApp] Jupyter Server 2.6.0 is running at:
    jupyter-matlab-container  | [I 2024-05-16 14:24:23.946 ServerApp] http://48f2034c1bd1:8888/lab?token=138ec9265e233897ebe7b6b9863476678fa81854c8dd06cc
    jupyter-matlab-container  | [I 2024-05-16 14:24:23.946 ServerApp]     http://127.0.0.1:8888/lab?token=138ec9265e233897ebe7b6b9863476678fa81854c8dd06cc
    
  4. Click on this link: http://127.0.0.1:8888/lab?token=138ec9265e233897ebe7b6b9863476678fa81854c8dd06cc Note: the token value will be different for you.
  5. Attempt to run the MATLABKernel from the Jupyter Lab notebook that is presented. image

Hopefully this information helps you configure your environment.

If not, please share the configuration files required to simulate your environment on my end to continue investigating.

Cheers Prabhakar

Additional Information:

  1. The jupyter-matlab-container used in the compose file is built based on this Dockerfile.
  2. These are the versions of the various matlab packages in that container:
    (base) jovyan@48f2034c1bd1:~$ python -m pip list | grep matlab
    jupyter-matlab-proxy          0.12.2
    matlab-proxy                  0.16.0
    matlabengine                  24.1 
    

prabhakk-mw avatar May 16 '24 14:05 prabhakk-mw