java.lang.InternalError: Can't connect to X11 window server for JVisualVM profiling session
Asked Answered
S

3

1

I have an Ubuntu server VM (myapp01) and have a Java application deployed there. The app has been acting wonky and I would like to profile it with JVisualVM. To do this I need to install X-Windows on my Windows 7 host, and then get the Ubuntu VM to export its X11 connection to my host when I tell it to run JVisualVM on the VM.

So I started by downloading XMing here:

http://sourceforge.net/projects/xming/files/Xming/6.9.0.31/Xming-6-9-0-31-setup.exe/download

I used all default/recommended installation options, including using a normal PuTTy session and allowing public & private network access. After installing XMing, I launched it and verified it was running on my Windows host. I then opened up Cygwin and SSHed into the Ubuntu server:

$ ssh myuser@myapp01
myuser@myapp01's password:
Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.5.0-23-generic x86_64)

* Documentation:  https://help.ubuntu.com/

System information as of Tue Jun 10 21:26:15 EDT 2014

System load:  0.0                Processes:           82
Usage of /:   22.5% of 11.81GB   Users logged in:     0
Memory usage: 30%                IP address for eth0: 10.10.41.108
Swap usage:   0%

    Graph this data and manage this system at:
    https://landscape.canonical.com/

38 packages can be updated.
30 updates are security updates.

Last login: Tue Jun 10 15:03:35 2014 from 10.10.101.96

I then export the display to what appears to be my host's IP:

myuser@myapp01:~$ export DISPLAY=10.10.101.96

I then attempt to run JVisualVM:

myuser@myapp01:~$ cd $JAVA_HOME
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64$ ls
bin  COPYRIGHT  db  include  jre  lib  LICENSE  man  README.html  release  src.zip  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64$ cd bin/
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64/bin$ ./jvisualvm
Error: Can't connect to X11 window server using '10.10.101.96' as the value of the DISPLAY variable.
See the /home/myuser/.visualvm/7u14/var/log/messages.log for details.
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64/bin$ vim /home/myuser/.visualvm/7u14/var/log/messages.log

Inside /home/myuser/.visualvm/7u14/var/log/messages.log:

java.lang.InternalError: Can't connect to X11 window server using '10.10.101.96' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
    at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
    at org.netbeans.core.startup.Main.start(Main.java:200)
    at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:84)
    at java.lang.Thread.run(Thread.java:745)

Ideas? I am VPNed in, could that be affecting anything? Do I have XMing misconfigured somehow? Is my export DISPLAY command wrong?

Scat answered 11/6, 2014 at 1:41 Comment(10)
Why the downvotes and closevotes sans any explanations? This site is for asking programming questions. The export DISPLAY command is a statement interpreted by a shell, hence it's a piece of script. Script is code. If my export is incorrect, which I believe it is, this question is about code.Scat
And if another SE site is more fit for this question, instead of downvoting it, please just move it!Scat
You may have some code to debug, but the problem is not with your code. It's your bog-standard dontknowhowtorunXoverssh question. There are superuser.stackexchange.com, askubuntu.stackexchange.com and unix.stackexchange.com for such questions. All have it asked and answered about a zillion times, but here you go again: (1) enable X forwarding in ssh; (1) do not set DISPLAY, it should be already set for you if you have done (1).Carlo
Thanks @n.m. (+1) - I'm confused though, are you saying that I need to enable X forwarding in SSH first, or to unset display first (your comment above has 2 "(1)" instructions in it)? Thanks for any help in clarifying the sequence here!Scat
A typo, yes. "do not set DISPLAY" should be (2). You do not unset DISPLAY, you ssh in and check that it's set (to something like localhost:10.0).Carlo
And to finish it off: you verify that X11Forwarding yes appears uncommented in your sshd config, if not then uncomment/add it, restart sshd, then ssh -Y to your host.Carlo
Do you have a JDK installed on your Windows7 box ? If yes, JVisualVM from Windows can easily monitor a remote host. If not you should try ssh -y ... see man ssh (unix side) for more detailsReprography
Thanks @SergeBallesta (+1) if it is true that JVisualVM allows remote host profiling, can you provide me with an answer for setting this up? Let's say that my VM is known to the network as myapp01. Thoughts?Scat
Normally DISPLAY will have IP address:display num. Have you missed :0 (or some number) in your export DISPLAY?Turret
Serge is right, also see: #6347761Bookmaker
V
9

For security purposes, X servers won’t generally accept direct TCP connections from other hosts. Otherwise people could connect keyloggers to your X server, and your keystrokes would pass over the network unencrypted, allowing people to record passwords just by being on the same LAN.

But SSH provides a secure way to forward X11 traffic over your SSH session, using the -X or -Y options.

On your windows computer, make sure $DISPLAY is set correctly by trying to open an xterm from the command line. $DISPLAY will probably be set to :0 which stands for localhost:0. There are also additional tokens used to authenticate connections to the X server that are stored in ~/.Xauthority that you can view with xauth list.

Now, run ssh -Y 10.10.101.96. If you get a message like X11 forwarding request failed on channel 0, then run ssh -v -Y 10.10.101.96 instead to get debugging messages. If the remote machine is a server, the reason will probably be that xauth isn’t installed. On CentOS, it’s in the xorg-x11-xauth RPM.

On the remote machine, if everything went well, then $DISPLAY on the remote machine will now be set to a proxy display set up by SSH:

$ echo $DISPLAY
localhost:10.0

At which point you can run a command like xterm on the remote machine, and have the window pop up on your local display.

Although there’s no X server running on the remote machine, you may still need to install a bunch of X11 libraries for Java to be able to talk to your local X server…

Vue answered 19/6, 2014 at 13:42 Comment(0)
R
0

If a JDK is installed on the Windows host, there is no need for using the JVisualVM from the Unix host through XWindow and ssh. It is a perfectly correct solution, but it can be tricky if you are not used to ssh and XWindow DISPLAY, not speaking of cygwin or XMing install ...

The simplest solution in this use case is :

  • run jstatd on the Linux host (preferently under same credentials of the app to debug)
  • run jvisualvm on the Windows host and ask it to connect to the Linux host

(see docs about jvisualvm and jstatd for further references)

Reprography answered 13/6, 2014 at 10:43 Comment(0)
S
0

I have solved a similar problem. In my case there was an incorrect IP-address specified in /etc/hosts file for a hostname of server running sshd.

Fortunately java application gave me this more verbose output, while other applications just fails with Failed to open display message.

Schechter answered 23/4, 2015 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.