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

Variable explorer doesn't show variables on remote kernel when using localhost forwarded ports #14894

Closed
6 of 9 tasks
MikeFair opened this issue Mar 9, 2021 · 10 comments · Fixed by #16890
Closed
6 of 9 tasks

Comments

@MikeFair
Copy link

MikeFair commented Mar 9, 2021

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • [x ] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

Simply put, it's the same behavior as Issue #11538 (recently marked resolved but seems like still an issue in this case)...
I connect to an existing remote kernel, but the variable explorer never populates.

In this case, the remote kernel is accessed via localhost forwarded ports over an SSH session.
I don't know if that matters or not.

The remote system uses two factor authentication to log in even on SSH shells.
I suspect the challenge response interactivity during the login session is unexpected by the typical "remote SSH connection" configuration the Spyder console expects. To get around this fact, or other firewall block issues, I forward the localhost ports over an existing SSH tunnel link. Putty makes it straightforward to configure the multiple ports required in a reusable session config.

Here's an online guide:
https://medium.com/@mazzine.r/how-to-connect-your-spyder-ide-to-an-external-ipython-kernel-with-ssh-putty-tunnel-e1c679e44154

What steps reproduce the problem?

  1. Start a Kernel on the remote system using --ip=127.0.0.1 and snag the json configuration file
  2. Use SSH port forwarding (e.g. PuTTY => Connection->SSH->Tunnels) to forward all remote ports in the config to localhost ports
  3. Copy the JSON config locally
  4. "Connect to an existing kernel" in Spyder, use the JSON config (bc of port forwards, no remote host config required)

What is the expected output? What do you see instead?

Expected: Variable explorer to populate
Actual: Variable Explorer remains completely blank, even if variables are assigned directly inside that console window

Versions

  • Spyder version: 4.2.3 (Latest as of submission)
  • Python version: 3.8.5
  • Qt version:
  • PyQt version:
  • Operating System name/version:
    Local Spyder: Windows 10
    Remote IPython Kernel: an updated RedHat based system I have no control over

Dependencies:
Remote IPython Kernel: 1.10.2

@steff456
Copy link
Member

steff456 commented Mar 9, 2021

Hi @MikeFair,

Thanks for reporting, @impact27 do you have any idea why this is not working as expected?

@ccordoba12
Copy link
Member

Hey @MikeFair, I think the problem is (as it was in #11538) that we have a non-standard port (called comms) which is not forwarded. That's because we create it at runtime, so it's not part of the kernel's json config file. Unfortunately, that port is in charge of all communications between the kernel and Spyder, so not only the Variable Explorer, but also the debugger stop working when it's not found.

What @impact27 did to solve issue #11538 was to forward that port when users enter their SSH credentials in our dialog for that. Since you're manually forwarding the kernel ports through Putty, his solution doesn't take effect.

So the solution would be to ditch that port and use instead a standard one. However, that became possible only a few weeks ago, thanks to ipython/ipykernel#585 (because we needed that port to be threaded).

But let's wait to hear from @impact27 to see if what I think is right.

@impact27
Copy link
Contributor

That is correct. The solutions I can think of are:
1- update the json config file to add the comms port, so you can update it
2- use the control process now that ipython/ipykernel#585 is merged (planned but potentially a lot of work)

@MikeFair
Copy link
Author

MikeFair commented Mar 10, 2021

When I looked at @impact27's patch to resolve #11538 this additional "comms port" did seem to be the missing piece, but as mentioned, wasn't in the JSON config. That being said, adding it to the JSON config, or at least giving me a way to query it at runtime, would be the easiest solutions.

Another solution might be to enable the SSH Connection dialog to handle more complex interactivity, enabling me to actually just log in via SSH to the remote machine, but (1) that seems like a stretch, and (2) it seems to me a "port forward friendly" solution would be preferable overall.

Out of curiosity I noticed that it appears Spyder is using ZeroMQ for its message routing. That being the case, what about creating a single "multiplex channel" that only uses a single OS level resource object (IP Port (default), Serial Port, Named Pipe, whatever) and then use ZMQ's queueing functions to multiplex all the Spyder comms over that backbone and eliminate the use of multiple ports and "future proofing" to enable as many separate channels internally as you'd like?

IIRC it's exactly one of the core use case scenarios ZMQ had in mind when it was constructed...

@impact27
Copy link
Contributor

impact27 commented Mar 10, 2021

@MikeFair Open the internal console (Panes > Internal console) Then type:
spy.window.ipyconsole.get_current_shellwidget().spyder_kernel_comm.remote_comm_port
That will give you the remote port that could be added in the json file for the current console

@impact27
Copy link
Contributor

Or merge spyder-ide/spyder-kernels#281

@impact27
Copy link
Contributor

Out of curiosity I noticed that it appears Spyder is using ZeroMQ for its message routing. That being the case, what about creating a single "multiplex channel" that only uses a single OS level resource object (IP Port (default), Serial Port, Named Pipe, whatever) and then use ZMQ's queueing functions to multiplex all the Spyder comms over that backbone and eliminate the use of multiple ports and "future proofing" to enable as many separate channels internally as you'd like?

We want to use ipython channels to be compatible with ipython kernels. Unfortunately, ipykernel was running all the channels in the same thread, so there was no way of doing something while the main thread was running. This is why we added a new channel. With the new version of ipykernel the control channel is running on a separate thread, solving this issue.

@venkateshsathya
Copy link

venkateshsathya commented Mar 12, 2021

Hi Guys,

I am facing the same issue. The way I am connecting is:

  1. I start a kernel on remote RedHat server.
  2. I do connect to existing kernel on local MacBook spyder SW, loading the JSON file copied from the remote machine.
  3. I enable the remote kernel via SSH checkbox and feed in the SSH login credentials.
  4. I have spyder 4.2.3 and remote server spyder kernel version 1.10.2
  5. I leave the port number in SSH connection as 22 (default)

As a temporary workaround, what would you guys suggest?.
I got the port number from spy.window.ipyconsole.get_current_shellwidget().spyder_kernel_comm.remote_comm_port command, say 56975 for my setup. How do I add it to the JSON file.

MY JSON contents are as follows. Do I create a separate field such as "comm_port": 56975.
Kindly advice since I am a novice to some of these concepts.

"{
"shell_port": 38614,
"iopub_port": 36826,
"stdin_port": 37991,
"control_port": 45116,
"hb_port": 56076,
"ip": "127.0.0.1",
"key": "23782bff-9ab7b00fa14a7a4490ac5f67",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
"

@impact27
Copy link
Contributor

impact27 commented Mar 12, 2021

@venkateshsathya Your use case should be covered by #14447. Make sure you have the latest version of spyder and spyder-kernels both locally and remotely.

The way it works is that the comm port number should be automatically transferred to the frontend by the other channels. So If you connect via ssh, the ports need to be forwarded. It should happen automatically since 4.2.2

@fohria
Copy link

fohria commented Nov 24, 2021

heya! any chance the pull request mentioend here will be merged soon? i suspect it may resolve my issue on variable explorer not updating properly (or at all) when connecting to remote kernel running in WSL2 on the same machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment