Connection has been gracefully closed
I get this message when I tried to connect to either 5901 or 5902 using a tightvnc client.
Connection has been gracefully closed
The services are running ok
● xvnc1.socket - XVNC Server 1
Loaded: loaded (/etc/systemd/system/xvnc1.socket; enabled; vendor preset: enabled)
Active: active (listening) since Fri 2023-01-20 17:07:44 EST; 5min ago
Listen: [::]:5901 (Stream)
Accepted: 2; Connected: 0;
Tasks: 0 (limit: 779)
CPU: 12ms
CGroup: /system.slice/xvnc1.socket
Jan 20 17:07:44 raspberrypi systemd[1]: Listening on XVNC Server 1.
● xvnc2.socket - XVNC Server 2
Loaded: loaded (/etc/systemd/system/xvnc2.socket; enabled; vendor preset: enabled)
Active: active (listening) since Fri 2023-01-20 17:07:44 EST; 5min ago
Listen: [::]:5902 (Stream)
Accepted: 0; Connected: 0;
Tasks: 0 (limit: 779)
CPU: 3ms
CGroup: /system.slice/xvnc2.socket
Jan 20 17:07:44 raspberrypi systemd[1]: Listening on XVNC Server 2
```.
I got this running on a 32 bit Bullseye rpi just last week. I recall I initially had this same issue, but I just can't recall what I did to fix it. Maybe played around with /boot/config.txt for display resolution.
Does the display resolution specified with -geometry need to be less than what's specified by the mode in /boot/config.txt. If so, what do I use for a mode that is just 1080p (no horizontal resolution indicated).
Easy question first: The resolutions using these virtual desktops have literally nothing to do with the resolution of the console display. These are virtual desktops, so can have any resolution you want. However, they will not enjoy the hardware acceleration that VNC on the console gets. This may or may not be an issue for you, depending on what you're trying to run.
As far as the problem you're having...can you please provide some additional information:
- system log showing the connection and disconnection
- What display manager are you using? (lightdm, xdm, etc)
- For that display manager, did you do the configuration as noted in the README?
I've probably forgotten something, but that should be enough to get started in chasing down this issue for you.
- Journal begins at Wed 2022-09-21 23:17:24 EDT, ends at Fri 2023-01-20 19:19:52 EST. -- Jan 20 19:13:24 raspberrypi kernel: Booting Linux on physical CPU 0x0000000000 [0x410fd034] Jan 20 19:13:24 raspberrypi kernel: Linux version 5.15.84-v8+ (dom@buildbot) (aarch64-linux-gnu-gcc-8 (Ubuntu/Linaro 8.> Jan 20 19:13:24 raspberrypi kernel: random: crng init done Jan 20 19:13:24 raspberrypi kernel: Machine model: Raspberry Pi 3 Model B Plus Rev 1.3 Jan 20 19:13:24 raspberrypi kernel: efi: UEFI not found. Jan 20 19:13:24 raspberrypi kernel: Reserved memory: created CMA memory pool at 0x000000001ec00000, size 256 MiB Jan 20 19:13:24 raspberrypi kernel: OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool Jan 20 19:13:24 raspberrypi kernel: Zone ranges: Jan 20 19:13:24 raspberrypi kernel: DMA [mem 0x0000000000000000-0x000000003b3fffff] Jan 20 19:13:24 raspberrypi kernel: DMA32 empty Jan 20 19:13:24 raspberrypi kernel: Normal empty Jan 20 19:13:24 raspberrypi kernel: Movable zone start for each node Jan 20 19:13:24 raspberrypi kernel: Early memory node ranges Jan 20 19:13:24 raspberrypi kernel: node 0: [mem 0x0000000000000000-0x000000003b3fffff] Jan 20 19:13:24 raspberrypi kernel: Initmem setup node 0 [mem 0x0000000000000000-0x000000003b3fffff] Jan 20 19:13:24 raspberrypi kernel: On node 0, zone DMA: 19456 pages in unavailable ranges Jan 20 19:13:24 raspberrypi kernel: percpu: Embedded 28 pages/cpu s77336 r8192 d29160 u114688 Jan 20 19:13:24 raspberrypi kernel: pcpu-alloc: s77336 r8192 d29160 u114688 alloc=28*4096 Jan 20 19:13:24 raspberrypi kernel: pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 Jan 20 19:13:24 raspberrypi kernel: Detected VIPT I-cache on CPU0 Jan 20 19:13:24 raspberrypi kernel: CPU features: kernel page table isolation forced ON by KASLR Jan 20 19:13:24 raspberrypi kernel: CPU features: detected: Kernel page table isolation (KPTI) Jan 20 19:13:24 raspberrypi kernel: CPU features: detected: ARM erratum 843419 Jan 20 19:13:24 raspberrypi kernel: CPU features: detected: ARM erratum 845719 Jan 20 19:13:24 raspberrypi kernel: Built 1 zonelists, mobility grouping on. Total pages: 238896 Jan 20 19:13:24 raspberrypi kernel: Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_als> Jan 20 19:13:24 raspberrypi kernel: Unknown kernel command line parameters "splash", will be passed to user space. Jan 20 19:13:24 raspberrypi kernel: Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes, linear) Jan 20 19:13:24 raspberrypi kernel: Inode-cache hash table entries: 65536 (order: 7, 524288 bytes, linear) Jan 20 19:13:24 raspberrypi kernel: mem auto-init: stack:off, heap alloc:off, heap free:off Jan 20 19:13:24 raspberrypi kernel: Memory: 665532K/970752K available (11520K kernel code, 1956K rwdata, 4136K rodata, > Jan 20 19:13:24 raspberrypi kernel: SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1 Jan 20 19:13:24 raspberrypi kernel: ftrace: allocating 38065 entries in 149 pages Jan 20 19:13:24 raspberrypi kernel: ftrace: allocated 149 pages with 4 groups Jan 20 19:13:24 raspberrypi kernel: trace event string verifier disabled Jan 20 19:13:24 raspberrypi kernel: rcu: Preemptible hierarchical RCU implementation. Jan 20 19:13:24 raspberrypi kernel: rcu: RCU event tracing is enabled.
lightdm
I connect fine to 5900 if I start x11vnc server
I do see this in /var/log/syslog after trying to connect and getting the "gracefully closed" message on the client. Note, there's a message in there saying the connection was succcessful
Jan 20 19:17:01 raspberrypi CRON[1442]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 20 19:19:03 raspberrypi systemd[1]: Started Session 5 of user pi.
Jan 20 19:22:32 raspberrypi systemd[1]: Created slice system-xvnc2.slice.
Jan 20 19:22:32 raspberrypi systemd[1]: Started XVNC Per-Connection Daemon 2 (192.168.0.113:56405).
Jan 20 19:22:32 raspberrypi Xtightvnc[1481]: Unrecognized option: -noreset
Jan 20 19:22:32 raspberrypi Xtightvnc[1481]: use: X [:
For that display manager, did you do the configuration as noted in the README?
Yes, triple checked.
Something appears to be wrong in the file /etc/systemd/system/xvnc2.service. Please post the contents of that file. Port 5900 and x11vnc are completely different animals from these virtual VNC sessions, btw.
Also, did you install tightvnc server or tigervnc server?
And what distro/version is this on?
Understand about them being different--just mentioned because that says it's not an issue with the client or specifying the wrong host.
[Unit] Description=XVNC Per-Connection Daemon 2
[Service] ExecStart=-/usr/bin/Xtightvnc -noreset -SecurityTypes None -inetd -query 127.0.0.1 -geometry 1880x920 -pn -once StandardInput=socket StandardOutput=socket StandardError=journal
Just noticed it's Xtightvnc, not Tiger. I just used your script to generate those files.
And yes, I installed Tigervnc. Changing the files to use it and trying over.
sudo apt-get install tigervnc-standalone-server xfonts-scalable xfonts-100dpi xfonts-75dpi Reading package lists... Done Building dependency tree... Done Reading state information... Done tigervnc-standalone-server is already the newest version (1.11.0+dfsg-2+deb11u1). xfonts-100dpi is already the newest version (1:1.0.4+nmu1.1). xfonts-75dpi is already the newest version (1:1.0.4+nmu1.1). xfonts-scalable is already the newest version (1:1.0.3-1.2). The following package was automatically installed and is no longer required: libfuse2 Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded. p
You can fix this by sudo editing /etc/systemd/system/xvnc*.service and either
- Changing Xtightvnc to XtigerVNC
- OR leave it as Xtightvnc and remove the '-noreset'
Was just going to write that I don't understand how you got to this state, but I see that the script will do this if BOTH tightvnc and tigervnc happen to be installed when you run the script.
I'll think about how to fix it. in the meantime, make one of the 2 changes I suggested above.
Ah--looks like whatever is installed LAST is what gets set up in the files your script copies
Yeah, quite familiar with using systemctl, systemd, etc.
Rebooting now--pretty sure it will work. I
Not quite. If both are installed it will use tightvnc but have the wrong switches enabled. The fix is twofold:
- Clear the extra switch settings if tightvnc
- If both tigervnc and tightvnc are installed, figure out which one to use by asking user.
Yeah, I redid the script, rebooted, same problem, but it still had Xtightvnc in the /etc/systemd/system stuff.
Trying removing the -noreset now. Tiger versus tight--just the fonts thing to worry about?
Removing the -norest didn't fix. Switching to tigervncserver
Yeah, I redid the script, rebooted, same problem, but it still had Xtightvnc in the /etc/systemd/system stuff.
Trying removing the -noreset now. Tiger versus tight--just the fonts thing to worry about?
I actually don't have the font problem any more. I use a different font for my xterms, and tbh I haven't tested tightvnc in quite some time.
FYI, here's the font I use now for my xterms: -misc-fixed-bold-r-normal--15-140-75-75-c-90-iso10646-1
Removing the -norest didn't fix. Switching to tigervncserver
That should fix it. Check the system log. The problem should be obvious there. If it's not, heave it here and I'll have a look at it.
Ok, thanks for the super fast attention! Quite impressed!
Tiger works fine. I'll check out tight tomorrow and post what happens.
Thanks!
Ok, thanks for the super fast attention! Quite impressed!
That's what happens if you catch me at my desk 🤣
Tiger works fine. I'll check out tight tomorrow and post what happens.
Thanks!
Great...got you unstuck, and you understand the issue. I'll get back to fixing the script soon....
Verified it works with Xtightvnc also.
Do you see a difference in performance between Xtightvnc and Xtigervnc? Also, is significant system resource used if there are xnvc socket/service pairs created and enabled, but nothing is connected to them?
Also, this package seems to target users who may not be comfortable with editing systemd files.
I was expecting the xnvc sessions to be started at user level, not root. I think that's the more typical usage case. If you don't want to add User= and Group= to the created systemd files, you might want to mention how to manually change them to have the sessions run under a specified user.
I'm now trying to figure out why the Qt widgets that normally display on :0 aren't showing up on 5900--I can connect to it with no problem and see a desktop, but not my GUI application widgets.
Ah, great to hear. I think tightvnc and tigervnc are fairly comparable performance-wise, but I've not seen any performance data to confirm/deny this.
The really cool thing about this method is that the cost of them when they are not being used is literally a systemd open socket. systemd listens on the socket specified in the .socket file, and fires up the corresponding service when a connection is received.
Contrast that with other methods of starting virtual VNC servers that leave the vncserver running all the time, consuming system resources, or require that you start it manually, which is a pain.
Also, this package seems to target users who may not be comfortable with editing systemd files.
I was expecting the xnvc sessions to be started at user level, not root. I think that's the more typical usage case. If you don't want to add User= and Group= to the created systemd files, you might want to mention how to manually change them to have the sessions run under a specified user.
I'm now trying to figure out why the Qt widgets that normally display on :0 aren't showing up on 5900--I can connect to it with no problem and see a desktop, but not my GUI application widgets.
What is the reason you'd want these to start as a user other than root? Have you tried it to verify that it works?
When I do
echo $DISPLAY
I get
ip_addr:1.0
and
ipaddr:2.0
With .socket files that look like this:
[Unit]
Description=XVNC Server 0
[Socket]
ListenStream=5900
Accept=yes
[Install]
WantedBy=sockets.target
Maybe I can get my GUI to ouput on 1:0 and 2:0, but now it outputs to 0:0.
Can I change what displays the vnc servers are using?
When I do
echo $DISPLAYI get
ip_addr:1.0
and
ipaddr:2.0
With .socket files that look like this:
[Unit] Description=XVNC Server 0 [Socket] ListenStream=5900 Accept=yes [Install] WantedBy=sockets.targetMaybe I can get my GUI to ouput on 1:0 and 2:0, but now it outputs to 0:0.
Can I change what displays the vnc servers are using?
Your code should be independent of the setting for $DISPLAY. It should use whatever DISPLAY is set to, not try to jam it to a specific setting. The value of DISPLAY for vnc sessions corresponds to the port number (:1 would be 5901, :2 would be 5902, etc). So, the only way to change the setting of DISPLAY is to change the port number. 5900 is used by RealVNC for the console (which also happens to be :0). If you aren't using RealVNC on your system, you can rejigger the xvnc port number for one of the sessions (a bit messy, but doable), but you will have created a very brittle, likely to break solution IMHO.
Port number isn't the issue--it's the server number (not sure if that's the right terminology).
There are two parts of the $DISPLAY, eg. 0.0 or 1.0.
The number to the right of the decimal point is the port. The one to the left is the XServer number.
It's really not my code, but rather the Qt framework. It will attempt to connect to whatever DISPLAY is specified by the DISPLAY environment variable. Normally, 0:0 (or 0:1), etc.
The servers that get created using systemd are like 1:0, 1:1, etc.
For whatever reason, I get a message from the app saying it cannot connect to server when I try DISPLAY=1:0. I'm researching how to change that, but it seems there should be a way to start as server 0:0 or 0:1 instead of 1:0 or 1:1.
Also, this package seems to target users who may not be comfortable with editing systemd files. I was expecting the xnvc sessions to be started at user level, not root. I think that's the more typical usage case. If you don't want to add User= and Group= to the created systemd files, you might want to mention how to manually change them to have the sessions run under a specified user. I'm now trying to figure out why the Qt widgets that normally display on :0 aren't showing up on 5900--I can connect to it with no problem and see a desktop, but not my GUI application widgets.
What is the reason you'd want these to start as a user other than root? Have you tried it to verify that it works?
The usual reasons one should avoid running code as root. For example, opening a terminal window from the desktop would allow deletion of ANY files.
Or, am I missing something?
When I use x11vnc, I can always see the output of my Qt application. Which port I use doesn't matter--it just determines what the client uses for connection.
I can start an x11vnc session while two Xtightvnc sessions are running that were started by the system service. When I connect to the port associated with the x11vnc, I see a desktop with my application output, but client connections to either of the two Xtightvnc servers shows only the desktop.
Expanding on the last post---
Two Xtightvnc servers get started via the systemd mechanism, ports 5900 and 5901.
I can connect to either of them and see a desktop, but not the output from my Qt app.
I can then start an x11vnc session on the host and connect with vnc client to 5902. The expected graphical output is shown.