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

Socket timeout when attempting to connect to iruby kernel #363

Closed
edsinclair opened this issue Jan 23, 2025 · 8 comments
Closed

Socket timeout when attempting to connect to iruby kernel #363

edsinclair opened this issue Jan 23, 2025 · 8 comments

Comments

@edsinclair
Copy link
Contributor

I'm attempting to run a notebook on MacOS Sonoma. I've followed the installation instructions and attempted to troubleshoot but am stuck. The python kernel is working fine, but the ruby kernel never connects. This is the contents of the log:

[I 2025-01-23 12:08:39.936 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2025-01-23 12:08:39.938 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2025-01-23 12:08:39.939 ServerApp] jupyterlab | extension was successfully linked.
[I 2025-01-23 12:08:39.940 ServerApp] notebook | extension was successfully linked.
[I 2025-01-23 12:08:40.019 ServerApp] notebook_shim | extension was successfully linked.
[I 2025-01-23 12:08:40.037 ServerApp] notebook_shim | extension was successfully loaded.
[I 2025-01-23 12:08:40.038 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2025-01-23 12:08:40.038 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2025-01-23 12:08:40.039 LabApp] JupyterLab extension loaded from /Users/eirik/.pyenv/versions/3.12.8/lib/python3.12/site-packages/jupyterlab
[I 2025-01-23 12:08:40.039 LabApp] JupyterLab application directory is /Users/eirik/.pyenv/versions/3.12.8/share/jupyter/lab
[I 2025-01-23 12:08:40.039 LabApp] Extension Manager is 'pypi'.
[I 2025-01-23 12:08:40.054 ServerApp] jupyterlab | extension was successfully loaded.
[I 2025-01-23 12:08:40.056 ServerApp] notebook | extension was successfully loaded.
[I 2025-01-23 12:08:40.056 ServerApp] Serving notebooks from local directory: /Users/eirik
[I 2025-01-23 12:08:40.056 ServerApp] Jupyter Server 2.15.0 is running at:
[I 2025-01-23 12:08:40.056 ServerApp] http://localhost:8888/tree?token=a941ada4610180eb810efdaf1a8e98ed1925d35e2ac83b56
[I 2025-01-23 12:08:40.056 ServerApp]     http://127.0.0.1:8888/tree?token=a941ada4610180eb810efdaf1a8e98ed1925d35e2ac83b56
[I 2025-01-23 12:08:40.056 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2025-01-23 12:08:40.059 ServerApp]

    To access the server, open this file in a browser:
        file:///Users/eirik/Library/Jupyter/runtime/jpserver-7136-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/tree?token=a941ada4610180eb810efdaf1a8e98ed1925d35e2ac83b56
        http://127.0.0.1:8888/tree?token=a941ada4610180eb810efdaf1a8e98ed1925d35e2ac83b56
[I 2025-01-23 12:08:40.137 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
[I 2025-01-23 12:08:55.779 ServerApp] Creating new notebook in
[I 2025-01-23 12:08:55.930 ServerApp] Saving file at /Untitled.ipynb
[I 2025-01-23 12:08:55.960 ServerApp] Kernel started: 2d0db5ee-8a5b-421f-9270-54f1244dd21d
[I 2025-01-23 12:08:56.325 ServerApp] Connecting to kernel 2d0db5ee-8a5b-421f-9270-54f1244dd21d.
[I 2025-01-23 12:08:56.328 ServerApp] Connecting to kernel 2d0db5ee-8a5b-421f-9270-54f1244dd21d.
[I 2025-01-23 12:08:56.332 ServerApp] Connecting to kernel 2d0db5ee-8a5b-421f-9270-54f1244dd21d.
[I 2025-01-23 12:08:56.429 ServerApp] Connecting to kernel 2d0db5ee-8a5b-421f-9270-54f1244dd21d.
[I 2025-01-23 12:08:56.617 ServerApp] Connecting to kernel  .
[I 2025-01-23 12:09:42.604 ServerApp] Creating new notebook in
[I 2025-01-23 12:09:42.651 ServerApp] Saving file at /Untitled1.ipynb
[I 2025-01-23 12:09:42.671 ServerApp] Kernel started: 9b7f8787-31ce-4f85-b0c7-f5817d147666
W, [2025-01-23T12:09:42.875881 #7207]  WARN -- : parent process poller thread started.
[W 2025-01-23 12:10:42.764 ServerApp] Timeout waiting for kernel_info reply from 9b7f8787-31ce-4f85-b0c7-f5817d147666
[I 2025-01-23 12:10:42.765 ServerApp] Connecting to kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666.
[I 2025-01-23 12:10:43.881 ServerApp] Connecting to kernel 2d0db5ee-8a5b-421f-9270-54f1244dd21d.
[W 2025-01-23 12:10:47.275 ServerApp] Nudge: attempt 10 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:10:52.287 ServerApp] Nudge: attempt 20 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:10:57.297 ServerApp] Nudge: attempt 30 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[I 2025-01-23 12:10:57.333 ServerApp] Saving file at /Untitled.ipynb
[W 2025-01-23 12:11:02.309 ServerApp] Nudge: attempt 40 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:11:03.139 ServerApp] Timeout waiting for kernel_info reply from 9b7f8787-31ce-4f85-b0c7-f5817d147666
[I 2025-01-23 12:11:03.140 ServerApp] Connecting to kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666.
[W 2025-01-23 12:11:07.321 ServerApp] Nudge: attempt 50 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:11:07.651 ServerApp] Nudge: attempt 10 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:11:12.332 ServerApp] Nudge: attempt 60 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[W 2025-01-23 12:11:12.662 ServerApp] Nudge: attempt 20 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666
[E 2025-01-23 12:11:12.766 ServerApp] Exception in callback <bound method WebSocketMixin.send_ping of <jupyter_server.services.kernels.websocket.KernelWebsocketHandler object at 0x1139e8050>>
    Traceback (most recent call last):
      File "/Users/eirik/.pyenv/versions/3.12.8/lib/python3.12/site-packages/tornado/ioloop.py", line 937, in _run
        val = self.callback()
              ^^^^^^^^^^^^^^^
      File "/Users/eirik/.pyenv/versions/3.12.8/lib/python3.12/site-packages/jupyter_server/base/websocket.py", line 162, in send_ping
        self.ping(b"")
      File "/Users/eirik/.pyenv/versions/3.12.8/lib/python3.12/site-packages/tornado/websocket.py", line 440, in ping
        raise WebSocketClosedError()
    tornado.websocket.WebSocketClosedError
[W 2025-01-23 12:11:17.344 ServerApp] Nudge: attempt 70 on kernel 9b7f8787-31ce-4f85-b0c7-f5817d147666

Any suggestions for troubleshooting this would be most welcome. Thanks.

@kojix2
Copy link
Member

kojix2 commented Jan 23, 2025

Hi @edsinclair

Unfortunately, the IRuby project does not have any active developers. I occasionally merge pull requests sent from volunteers, even though I don't understand the details of IRuby's implementation very well. Are you using Ruby version 3.4? Currently, Ruby 3.4 does not pass the tests, so it may not work for several months until someone contributes a pull request...

If you are using a different version, it might be possible to get it working.

@kojix2
Copy link
Member

kojix2 commented Jan 23, 2025

Hmm?
On my Mac, Ruby 3.4.1 also works. Forget my earlier comment.

@edsinclair
Copy link
Contributor Author

@kojix2 thanks for the response. I'm using Ruby 3.3.6 installed using ruby-install

which ruby
/Users/eirik/.rubies/ruby-3.3.6/bin/ruby

The iruby register --force command appears to set things up correctly:

✗ cat /Users/eirik/Library/Jupyter/kernels/ruby3/kernel.json
{
  "argv": [
    "/Users/eirik/.rubies/ruby-3.3.6/bin/ruby",
    "/Users/eirik/.gem/ruby/3.3.6/bin/iruby",
    "kernel",
    "-f",
    "{connection_file}"
  ],
  "display_name": "Ruby 3 (iruby kernel)",
  "language": "ruby",
  "metadata": {
    "debugger": false
  }
}

I'm wondering if it has something to do with zeromq and Mac OS firewall settings... but that is the only idea I can think of right now.

@edsinclair
Copy link
Contributor Author

I just verified that the python process spawns a ruby process when I attempt to open a notebook with the ruby kernel:

Image

But for some reason the ruby process stays pegged at 100% CPU, which would seem to be a symptom closely related to the socket timeout... A second python process is spawned when I open a notebook with the python kernel, but after an initial CPU usage spike it drops to an idle state. @kojix2 when you open a ruby notebook do you get this same WARN line in your log?

[I 2025-01-23 13:30:53.903 ServerApp] Kernel started: 3f086022-0653-405c-ae00-fc56096aca8a
W, [2025-01-23T13:30:54.184404 #16261]  WARN -- : parent process poller thread started.

@edsinclair
Copy link
Contributor Author

A quick update. I've been trying to run this from a directory with a Gemfile and I decided to clear out all the gems except for iruby, ffi-rzmq and that resulted in the ability for the notebook to connect to the Ruby kernel. Now I have a different error that appears in the notebook output when I attempt to execute ruby code (In this case a simple puts statement)

NoMethodError: undefined method `build_statement' for an instance of IRB::Irb
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/backend.rb:60:in `eval'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/backend.rb:16:in `eval'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/kernel.rb:204:in `execute_request'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/kernel.rb:139:in `dispatch'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/kernel.rb:127:in `run'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/kernel_app.rb:90:in `run_kernel'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/kernel_app.rb:13:in `run'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/lib/iruby/application.rb:110:in `run'
/Users/eirik/.gem/ruby/3.3.6/gems/iruby-0.8.0/exe/iruby:7:in `<top (required)>'
/Users/eirik/.gem/ruby/3.3.6/bin/iruby:25:in `load'
/Users/eirik/.gem/ruby/3.3.6/bin/iruby:25:in `<main>'

@edsinclair
Copy link
Contributor Author

@kojix2 So it looks like build_statement was replaced with parse_input a couple of weeks ago:

ruby/irb@9fc14eb

So the handling in eval here: https://github.com/SciRuby/iruby/blob/master/lib/iruby/backend.rb#L64
needs to be updated. I can take a stab at it if you'd be interested in a PR...

@kojix2
Copy link
Member

kojix2 commented Jan 23, 2025

@edsinclair
Thank you for investigating the cause of the error message.
I see that the IRB has recently changed. I think this is an important finding. Please send us a pull request.

@edsinclair
Copy link
Contributor Author

For others who might find this thread in the future. The original problem was caused by the presence of the activesupport gem in the Gemfile of the directory I starting my notebook server from. Removing it and re-bundling allowed the ruby kernel to start without getting stuck at 100% CPU. And with the fix in #364 I have a working notebook 🙌

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

No branches or pull requests

2 participants