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

wrong jupyter server port number in a specific situation #1170

Closed
KubaOfca opened this issue Jan 10, 2023 · 5 comments · Fixed by #1229
Closed

wrong jupyter server port number in a specific situation #1170

KubaOfca opened this issue Jan 10, 2023 · 5 comments · Fixed by #1229
Labels

Comments

@KubaOfca
Copy link

KubaOfca commented Jan 10, 2023

Description

I can't start the new jupyter lab server on a given port when the server that was previously running on this port has just been shut down. Previously, when I was using version 1.23.4, this error did not occur. Moreover, when I wait a bit (let's say 5 min) after shutting down jupyter lab server, I am able to run it on the desired port.

Reproduce

  1. create conda environment conda create -n env_name
  2. activate the environment conda activate env_name
  3. install jupyter lab conda install jupyterlab -c conda-forge
  4. start jupyter lab server on specific port jupyter lab --port 1234
  5. after a few seconds, close the jupyter lab server Ctrl-C
  6. start jupyter lab server again on the same port jupyter lab --port 1234
  7. jupyter lab server is running on port 1235 instead of 1234.

Expected behavior

After shutting down the jupyter lab server running on port 1234, it is possible to restart the jupyter lab server on the same specified port 1234.

Context

  • Operating System and version: Ubuntu 22.04.1 LTS
  • Browser and version: Mozilla Firefox 108.0.2 (64-bit)
  • Jupyter Server version: 2.0.6
Command Line Output
jupyter lab --port 1234
[I 2023-01-10 09:58:23.315 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2023-01-10 09:58:23.317 ServerApp] jupyterlab | extension was successfully linked.
[I 2023-01-10 09:58:23.318 ServerApp] nbclassic | extension was successfully linked.
[I 2023-01-10 09:58:23.410 ServerApp] notebook_shim | extension was successfully linked.
[I 2023-01-10 09:58:23.492 ServerApp] notebook_shim | extension was successfully loaded.
[I 2023-01-10 09:58:23.492 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2023-01-10 09:58:23.493 LabApp] JupyterLab extension loaded from /home/jakub/miniconda3/envs/test_2/lib/python3.11/site-packages/jupyterlab
[I 2023-01-10 09:58:23.493 LabApp] JupyterLab application directory is /home/jakub/miniconda3/envs/test_2/share/jupyter/lab
[I 2023-01-10 09:58:23.494 ServerApp] jupyterlab | extension was successfully loaded.
[I 2023-01-10 09:58:23.495 ServerApp] nbclassic | extension was successfully loaded.
[I 2023-01-10 09:58:23.495 ServerApp] Serving notebooks from local directory: /home/jakub/Desktop
 [I 2023-01-10 09:58:23.495 ServerApp] Jupyter Server 2.0.6 is running at:
[I 2023-01-10 09:58:23.495 ServerApp] http://localhost:1234/lab?token=46f218262a185ea765bee8f2ee09a362b06a7289c15649c1
[I 2023-01-10 09:58:23.495 ServerApp]  or http://127.0.0.1:1234/lab?token=46f218262a185ea765bee8f2ee09a362b06a7289c15649c1
[I 2023-01-10 09:58:23.495 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2023-01-10 09:58:23.514 ServerApp] 
To access the server, open this file in a browser:
    file:///home/jakub/.local/share/jupyter/runtime/jpserver-5834-open.html
Or copy and paste one of these URLs:
    http://localhost:1234/lab?token=46f218262a185ea765bee8f2ee09a362b06a7289c15649c1
 or http://127.0.0.1:1234/lab?token=46f218262a185ea765bee8f2ee09a362b06a7289c15649c1

0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[W 2023-01-10 09:58:26.008 LabApp] Could not determine jupyterlab build status without nodejs
[I 2023-01-10 09:58:44.267 ServerApp] Shutting down on /api/shutdown request.
[I 2023-01-10 09:58:44.267 ServerApp] Shutting down 4 extensions
(test_2) jakub@jakub:~/Desktop$ jupyter lab --port 1234
[I 2023-01-10 09:59:03.907 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2023-01-10 09:59:03.909 ServerApp] jupyterlab | extension was successfully linked.
[I 2023-01-10 09:59:03.911 ServerApp] nbclassic | extension was successfully linked.
[I 2023-01-10 09:59:03.999 ServerApp] notebook_shim | extension was successfully linked.
[I 2023-01-10 09:59:04.079 ServerApp] notebook_shim | extension was successfully loaded.
[I 2023-01-10 09:59:04.080 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2023-01-10 09:59:04.080 LabApp] JupyterLab extension loaded from /home/jakub/miniconda3/envs/test_2/lib/python3.11/site-packages/jupyterlab
[I 2023-01-10 09:59:04.080 LabApp] JupyterLab application directory is /home/jakub/miniconda3/envs/test_2/share/jupyter/lab
[I 2023-01-10 09:59:04.081 ServerApp] jupyterlab | extension was successfully loaded.
[I 2023-01-10 09:59:04.082 ServerApp] nbclassic | extension was successfully loaded.
[I 2023-01-10 09:59:04.082 ServerApp] The port 1234 is already in use, trying another port.
[I 2023-01-10 09:59:04.083 ServerApp] Serving notebooks from local directory: /home/jakub/Desktop
[I 2023-01-10 09:59:04.083 ServerApp] Jupyter Server 2.0.6 is running at:
[I 2023-01-10 09:59:04.083 ServerApp] http://localhost:1235/lab?token=9aaba670f7306be9d99c65a31f069521ab0f9a1717a821f7
[I 2023-01-10 09:59:04.083 ServerApp] or http://127.0.0.1:1235/lab?token=9aaba670f7306be9d99c65a31f069521ab0f9a1717a821f7
[I 2023-01-10 09:59:04.083 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2023-01-10 09:59:04.101 ServerApp]

To access the server, open this file in a browser:
    file:///home/jakub/.local/share/jupyter/runtime/jpserver-6104-open.html
Or copy and paste one of these URLs:
    http://localhost:1235/lab?token=9aaba670f7306be9d99c65a31f069521ab0f9a1717a821f7
 or http://127.0.0.1:1235/lab?token=9aaba670f7306be9d99c65a31f069521ab0f9a1717a821f7

0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[W 2023-01-10 09:59:06.578 LabApp] Could not determine jupyterlab build status without nodejs
[I 2023-01-10 09:59:18.427 ServerApp] Shutting down on /api/shutdown request.
[I 2023-01-10 09:59:18.428 ServerApp] Shutting down 4 extensions

Additional information

I've tried reproducing this step on Windows as well as Github Action CI and the error I described above doesn't occur here. In addition, I checked on Ubuntu 22.04.1 what will happen when I change the jupyter_server version from 2.0.6 to 1.23.4. After this change I was able to start the servers on the right ports.

Possible solution

The problem seems to disappear when I replace _find_http_port with _bind_http_server_tcp in serverapp.py (I manually edited serverapp.py after downloading the jupyter_server 2.0.6 package) which was present in jupyter_server 1.23.4. After this change, I can start the servers on the right ports on Ubuntu 22.04.01.

@KubaOfca KubaOfca added the bug label Jan 10, 2023
@welcome
Copy link

welcome bot commented Jan 10, 2023

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@davidbrochart
Copy link
Contributor

Thanks for reporting the issue @KubaOfca. I also noticed it lately.

@KubaOfca
Copy link
Author

@davidbrochart
If I may ask, when do you plan to patch it ?

@dlqqq
Copy link
Contributor

dlqqq commented Mar 1, 2023

I've also noticed the issue where the Jupyter Server sometimes fails to respect SIGINT (Ctrl-C), but the author seems to have closed it prematurely. I think these two are somehow related, but I'm not certain.

@blink1073
Copy link
Collaborator

This appears to be caused by the browser having an open connection on the port after the server is shut down. If I start with jupyter lab --no-browser --port 1234, then I cannot reproduce the error. If I ignore the errno.EADDRINUSE and use the port anyway, the application starts again just fine on port 1234. It seems like using sock.bind isn't a good enough indicator of whether we can claim the port.

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

Successfully merging a pull request may close this issue.

4 participants