4

I'm using MATLAB (2013a) on a linux machine remotely. I'm forwarding X11 via ssh using ssh -X (OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013). The X11 server is XQuartz 2.7.4 (xorg-server 1.13.0) on a Mac OS 10.8.5.

When my MATLAB crashes, it somehow kills the X11 connection, and I need to reconnect via ssh to re-estabilish a fresh X11, otherwise MATLAB refuses to start. Is it normal for an X11 application to do things like this? Is there a way to fix the X11 without reconnecting via ssh?

This happens when I don't have splash (-nosplash), no gui, no editor, no plots as well.

EDIT: I am running MATLAB over a shell (bash) inside tmux (or sometimes screen).

Memming
  • 1,731
  • 13
  • 25
  • Are you launching MATLAB via the `ssh` command or manually after you get a shell? – chappjc Oct 04 '13 at 18:27
  • @chappjc I run it via `screen` or `tmux`. updated the question. – Memming Oct 04 '13 at 18:56
  • `tmux` is nice! Anyway, I had a couple questions in my initial answer. Can you have a look? – chappjc Oct 04 '13 at 19:09
  • @chappjc I will. When it crashes next time which should be soonish. – Memming Oct 04 '13 at 19:42
  • 1
    Nice question, I always had this issue and never though of making a question trying to figure it out. – Werner Oct 05 '13 at 00:18
  • @Werner are you also using Mac OS? I wonder if this happens in linux as well... – Memming Oct 06 '13 at 18:54
  • @Memming I use Mac OS. But the issue that would happened for me (and other people from my laboratory) is that when we connect remotely to a screen on the laboratory server and run matlab, if matlab would crash, it would make the screen quite crazy (you wouldn't be able to see what you are typing and when you press enter it would show the bash `PS1` line again). The only way would finish the screen and reopen it. Have you tried ssh -Y as chappjc recommends? – Werner Oct 06 '13 at 19:47
  • 1
    @Werner when your terminal is messed up, you can always try `reset` and/or `stty sane`. :) – Memming Oct 06 '13 at 21:50
  • I see, didn't know about that. I'll try if this happens to me again x) – Werner Oct 07 '13 at 00:11
  • 1
    For testing purposes it may be convenient to have a way to crash Matlab. @Amro has found something for that in response to this question: http://stackoverflow.com/questions/16342688/difference-between-empty-matlab-struct-s-and-all-elements-s – Dennis Jaheruddin Oct 07 '13 at 08:04
  • So you log in to the linux box using ssh -X, then you start tmux/screen, then you start matlab – correct? Did you try whether the problem also happens without tmux/screen? If not, you could simply use several ssh logins in several MacOS terminal windows instead. – A. Donda Oct 07 '13 at 19:21
  • @Memming - Please give the -Y syntax a shot, since it is given a as a potential solution by the MathWorks for exactly this problem: http://www.mathworks.com/support/solutions/en/data/1-1NDEZ0/?product=SL&solution=1-1NDEZ0 – chappjc Oct 09 '13 at 18:38
  • 1
    Wow, you really can crash MATLAB with just `S = struct(); S = setfield(S, {}, 'g', {}, 0)`! Nice tip for crazy people like us. – chappjc Oct 09 '13 at 18:46

2 Answers2

4

You need to have the DISPLAY variable set properly for X11 forwarding to work correctly -- something ssh -X or ssh -Y should do for you. What is the value of DISPLAY before and after the crash (echo $DISPLAY)? It should be something like localhost:10.0. I'm wondering if the variable gets messed up does not exit cleanly.

Also, try using -Y instead of -X to see if that makes any difference. If that doesn't help, try adding ForwardX11Trusted yes in /etc/ssh/ssh_config.

chappjc
  • 30,359
  • 6
  • 75
  • 132
2

It would be helpful to show the complete sequence of commands you use to initiate the connection and start MATLAB, along with any error messages. For example:

# batch mode
client$ ssh -v -x user@server           # small "x" disables X11 forwarding
server$ unset DISPLAY
server$ nohup matlab -nodesktop -nodisplay -noFigureWindows -nosplash \
          -r "ver; quit;" > m_output.out 2>&1 < /dev/null &

# interactive mode
client$ export DISPLAY=localhost:0.0
client$ ssh -v -X user@server           # enable X11 forwarding
server$ matlab

A few ideas:

  • turn on more verbose output (ssh -vv), and investigate the reason the SSH connection was closed (debug output messages or any log files)

  • are you directly running a command from ssh, or is this done in two steps (connect using ssh, then interactively start command from allocated shell)?

  • If I understood correctly, this also happens when not using X11 forwarding?

  • does this happen when using nohup or screen/tmux as well? See this

  • try adding TCPKeepAlive to your ssh config

  • how about using auto-reconnect SSH connections

  • are you using any custom SSH configurations? (if so show the relevant parts from ssh_config and sshd_config files)

  • try running another process in the background before starting MATLAB

It's been reported before that MATLAB can sometimes mess up the bash shell when it returns. MathWorks recommended using a different shell instead (like tcsh or zsh).

Community
  • 1
  • 1
Amro
  • 123,847
  • 25
  • 243
  • 454