mathworks / jupyter-matlab-proxy

MATLAB Integration for Jupyter enables you to run MATLAB code in Jupyter Notebooks and other Jupyter environments. You can also open MATLAB in a browser directly from your Jupyter environment to use more MATLAB features.
Other
275 stars 36 forks source link

Setting Session Timeout #93

Closed kkrick-sdsu closed 1 month ago

kkrick-sdsu commented 3 months ago

Is it possible to set the session timeout when using MATLAB in a browser?

It would appear that this is using MATLAB Online which supports configuration for session timeouts but I have not been able to find the file specified.

I am using the MATLAB Integration for Jupyter in a Docker Container.

Thanks!

prabhakk-mw commented 3 months ago

Hi @kkrick-sdsu

Haven't read all the links as I'm mobile, but does the environment variable MWI_SHUTDOWN_ON_IDLE_TIMEOUT as described in the advanced usage readme serve the purpose?

kkrick-sdsu commented 3 months ago

Thanks, I will give this a try and share an update here.

prabhakk-mw commented 3 months ago

Hey @kkrick-sdsu

Did that environment variable serve the purpose?

kkrick-sdsu commented 3 months ago

Thanks for following up! I am reaching out to the user for confirmation if this change resolved the timeout issue.

prabhakk-mw commented 2 months ago

@kkrick-sdsu , any news?

kkrick-sdsu commented 2 months ago

Awaiting confirmation from the user, will let you asap.

kkrick-sdsu commented 2 months ago

Hello,

The user has tested this updated container image and confirmed that this does not solve the problem.

Is there anything else that I could try?

prabhakk-mw commented 2 months ago

Let's begin with a description of the issue.

Assuming that you are working with this Dockerfile

Thanks

PS: It might be easier to communicate with each other if you or your user is able to get in touch with us through MathWorks Technical Support .

kkrick-sdsu commented 2 months ago

Below is the full Dockerfile that we are using.

# Copyright 2021-2022 The MathWorks, Inc.
# Builds Docker image with 
# 1. MATLAB - Using MPM
# 2. MATLAB Integration for Jupyter
# on a base image of jupyter/base-notebook.

## Sample Build Command:
# docker build --build-arg MATLAB_RELEASE=r2022a \
#              --build-arg MATLAB_PRODUCT_LIST="MATLAB Deep_Learning_Toolbox Symbolic_Math_Toolbox"\
#              --build-arg LICENSE_SERVER=12345@hostname.com \
#              -t my_matlab_image_name .

# Specify release of MATLAB to build. (use lowercase, default is r2022a)
ARG MATLAB_RELEASE=r2023a

# Specify the list of products to install into MATLAB, 
ARG MATLAB_PRODUCT_LIST="MATLAB Curve_Fitting_Toolbox Image_Processing_Toolbox Statistics_and_Machine_Learning_Toolbox"

# Optional Network License Server information
ARG LICENSE_SERVER

# If LICENSE_SERVER is provided then SHOULD_USE_LICENSE_SERVER will be set to "_use_lm"
ARG SHOULD_USE_LICENSE_SERVER=${LICENSE_SERVER:+"_with_lm"}

# Default DDUX information
ARG MW_CONTEXT_TAGS=MATLAB_PROXY:JUPYTER:MPM:V1

# # Base Jupyter image without LICENSE_SERVER
# FROM jupyter/base-notebook AS base_jupyter_image

# # Base Jupyter image with LICENSE_SERVER
# FROM jupyter/base-notebook AS base_jupyter_image_with_lm

ARG BASE_CONTAINER=gitlab-registry.nrp-nautilus.io/prp/jupyter-stack/scipy:v1.3
FROM $BASE_CONTAINER

ENV MLM_LICENSE_FILE=${LICENSE_SERVER}

# Select base Jupyter image based on whether LICENSE_SERVER is provided
#FROM base_jupyter_image${SHOULD_USE_LICENSE_SERVER}
ARG MW_CONTEXT_TAGS
ARG MATLAB_RELEASE
ARG MATLAB_PRODUCT_LIST

# Switch to root user
USER root
ENV DEBIAN_FRONTEND="noninteractive" TZ="Etc/UTC"

## Installing Dependencies for Ubuntu 20.04
# For MATLAB : Get base-dependencies.txt from matlab-deps repository on GitHub
# For mpm : wget, unzip, ca-certificates
# For MATLAB Integration for Jupyter : xvfb
# List of MATLAB Dependencies for Ubuntu 20.04 and specified MATLAB_RELEASE
ARG MATLAB_DEPS_REQUIREMENTS_FILE="https://raw.githubusercontent.com/mathworks-ref-arch/container-images/main/matlab-deps/${MATLAB_RELEASE}/ubuntu22.04/base-dependencies.txt"
ARG MATLAB_DEPS_REQUIREMENTS_FILE_NAME="matlab-deps-${MATLAB_RELEASE}-base-dependencies.txt"

# Install dependencies
RUN wget ${MATLAB_DEPS_REQUIREMENTS_FILE} -O ${MATLAB_DEPS_REQUIREMENTS_FILE_NAME} && \
    export DEBIAN_FRONTEND=noninteractive && apt-get update && \
    xargs -a ${MATLAB_DEPS_REQUIREMENTS_FILE_NAME} -r apt-get install --no-install-recommends -y \
    wget \
    unzip \
    ca-certificates \
    xvfb \
    && apt-get clean \
    && apt-get -y autoremove \
    && rm -rf /var/lib/apt/lists/*

# Run mpm to install MATLAB in the target location and delete the mpm installation afterwards
RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm && \ 
    chmod +x mpm && \
    ./mpm install \
    --release=${MATLAB_RELEASE} \
    --destination=/opt/matlab \
    --products ${MATLAB_PRODUCT_LIST} && \
    rm -f mpm /tmp/mathworks_root.log && \
    ln -s /opt/matlab/bin/matlab /usr/local/bin/matlab

# # Install patched glibc - See https://github.com/mathworks/build-glibc-bz-19329-patch
# WORKDIR /packages
# RUN export DEBIAN_FRONTEND=noninteractive && \
#     apt-get update && apt-get clean && apt-get autoremove && \
#     wget -q https://github.com/mathworks/build-glibc-bz-19329-patch/releases/download/ubuntu-focal/all-packages.tar.gz && \
#     tar -x -f all-packages.tar.gz \
#     --exclude glibc-*.deb \
#     --exclude libc6-dbg*.deb && \
#     apt-get install --yes --no-install-recommends --allow-downgrades ./*.deb && \
#     rm -fr /packages
WORKDIR /

# Optional: Install MATLAB Engine for Python, if possible. 
# Note: Failure to install does not stop the build.
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
    && apt-get install --no-install-recommends -y  python3-distutils \
    && apt-get clean \
    && apt-get -y autoremove \
    && rm -rf /var/lib/apt/lists/* \
    && cd /opt/matlab/extern/engines/python \
    && python setup.py install || true

# Install additional software in /opt/
WORKDIR /opt

# To-Do: This may not be needed with user-installed version
# Install Pulmonary Toolkit: https://github.com/tomdoel/pulmonarytoolkit
RUN git clone https://github.com/tomdoel/pulmonarytoolkit.git \
    && chown -R jovyan:users /opt/pulmonarytoolkit/

ENV PATH /opt/pulmonarytoolkit/bin:$PATH

# Install rclone
RUN curl https://rclone.org/install.sh | bash

# Install desktop OS dependencies
RUN apt-get -y update \ 
 && apt-get -y install \
    icedtea-netx \
    net-tools \
    dbus-x11 \
    firefox \
    xfce4 \
    xfce4-panel \
    xfce4-session \
    xfce4-settings \
    xorg \
    xubuntu-icon-theme \
    tigervnc-standalone-server \
    tigervnc-xorg-extension \
 && apt-get remove -y -q light-locker \
 && apt clean && rm -rf /var/lib/apt/lists/* \
 && fix-permissions "${CONDA_DIR}" \
 && fix-permissions "/home/${NB_USER}"

# Install NBIA Data Retriever https://wiki.cancerimagingarchive.net/display/NBIA/Downloading+TCIA+Images
RUN wget -O nbia-data-retriever-4.4.1.deb "https://cbiit-download.nci.nih.gov/nbia/releases/ForTCIA/NBIADataRetriever_4.4.1/nbia-data-retriever-4.4.1.deb" \
 && dpkg -i nbia-data-retriever-4.4.1.deb

RUN echo -e "jovyan ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

# Switch back to notebook user
USER $NB_USER
WORKDIR /home/${NB_USER}

# Install MATLAB integration
RUN python -m pip install jupyter-matlab-proxy matlab_kernel

# Ensure jupyter-server-proxy JupyterLab extension is installed
#RUN jupyter labextension install @jupyterlab/server-proxy

# Install Jupyter Desktop
RUN /opt/conda/bin/conda install -c manics websockify
RUN pip install jupyter-remote-desktop-proxy

# Make JupyterLab the default environment
ENV JUPYTER_ENABLE_LAB="yes"

ENV MW_CONTEXT_TAGS=${MW_CONTEXT_TAGS}

# Set timeout to 2 weeks
ENV MWI_SHUTDOWN_ON_IDLE_TIMEOUT=20160
prabhakk-mw commented 2 months ago

Thank you @kkrick-sdsu !

The environment variable MWI_SHUTDOWN_ON_IDLE_TIMEOUT is not designed to cater to this case, so might be inconsequential to the issue being reported.

A few more followup questions to help investigate the issue:

  1. Does MATLAB crash? or exit unexpectedly? Are there any crash logs that you can find?

  2. Is the Jupyter Lab instance still running? Have you configured any kind of cullers at the Jupyter level ?

  3. Does the researcher start a Jupyter notebook, or directly use the MATLAB IDE from the Jupyter Lab interface?

  4. Does this issue only arise with a particular kind of script or happens with all long running scripts?

  5. Does the MATLAB instance consistently go away exactly at the 2 hour mark, or is it variable ?

  6. Are there any Jupyter Server logs that you have access to that you could share ?

kkrick-sdsu commented 2 months ago

Hi @prabhakk-mw ,

  1. MATLAB crashes with the error message "Either this integration terminated or the session ended". No logs at this point, but I will ask the user to set up another run and then see if crash logs get generated.
  2. JupyterLab instance was still running. We do have cullers configured, but they only kick in once there is no activity for ~2 days.
  3. Using MATLAB IDE from JupyterLab interface
  4. Happens with all long running scripts.
  5. No, it is variable. User reported it happening once at 5 hours and and once at 8 hours into their runs.
  6. No logs from Jupyter server currently, but I can ask the user to kick off a run and let me know so that I can grab any relevant logs.

Thanks, Kyle

prabhakk-mw commented 1 month ago

Thank you @kkrick-sdsu

"Either this integration terminated or the session ended".

This implies that the underlying webserver process ( ie: matlab-proxy-app) itself has been terminated. This could either because it crashed or that it was culled.

I don't think that this is because of MATLAB crashing, its most likely because something caused matlab-proxy-app to be terminated which in turn terminates the MATLAB child process.

prabhakk-mw commented 1 month ago

@kkrick-sdsu Any luck with finding the logs from Jupyter?

kkrick-sdsu commented 1 month ago

Hi @prabhakk-mw

No, I have not. I think we can close this issue as I don't have a way to reproduce in my own environment to get those logs.

-Kyle

prabhakk-mw commented 1 month ago

Thank you for your response @kkrick-sdsu

In case your user is still facing this issue, and would like our assistance kindly direct him to create a service request using the link below:

https://supportcases.mathworks.com/mwsupport/s/casetypeselection?language=en_US&c__caseParameter=productusage&s_tid=srlp_product

Referring to this issue should have him routed to the right teams.