6

Does X-Window have a maximum number limit on clients?

For example, can you create "unlimited" number of evince processes with windows? If not, what places the limit?

For another example (although I will use wine clients as examples below, I think the answer might or might not depend on whether X clients are wine-related or not), on Lubuntu 18.04

 $ evince my.pdf 
Maximum number of clients reachedUnable to init server: Could not connect: Connection refused
Cannot parse arguments: Cannot open display: 

$ wine PDFXCview.exe my.pdf 
047d:fixme:ver:GetCurrentPackageId (0x32fbc4 (nil)): stub
Maximum number of clients reached047d:err:winediag:x11drv_init_thread_data x11drv: Can't open display: :0. Please ensure that your X server is running and that $DISPLAY is set correctly.

After I close some windows (either .exe program's windows or evince windows), I can open new windows (for other pdf files).

I have used the .exe program to open 102 windows, and evince to open 5 windows. Are the windows too many for the X server? How can I solve the problem?

Can I raise the maximum number limit? Is there some configuration setting that limits the number of clients? How can I reconfigure it?

I read https://askubuntu.com/questions/4499/how-can-i-diagnose-debug-maximum-number-of-clients-reached-x-errors and What is the max number of x-clients?, but still can't figure out my problem.

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977

1 Answers1

10

From xorg.conf(5):

SERVERFLAGS SECTION
    ...
    Option "MaxClients"  "integer"
        Set  the  maximum  number of clients allowed to connect to the X
        server.  Acceptable values are 64, 128, 256 or 512.

And from Xserver(1):

-maxclients
      64|128|256|512  Set  the  maximum  number of clients allowed to
      connect to the X server.  Acceptable values are 64, 128, 256 or 512.

The default is 256, but could be raised to 2048 in recent versions of the X server:

./include/misc.h:#define MAXCLIENTS       2048
./include/misc.h:#define LIMITCLIENTS   256     /* Must be a power of 2 and <= MAXCLIENTS */
./os/osinit.c:int LimitClients = LIMITCLIENTS;

You can check NextAvailableClient() in dix/dispatch.c and AllocNewConnection() in os/connection.c for all the details.


On many linux distros, you can use this to set the client limit to 512:

# printf 'Section "ServerFlags"\n\tOption "MaxClients" "512"\nEndSection\n' \
        > /etc/X11/xorg.conf.d/99-maxclients.conf

Trying to run the Xorg binary (the real binary, not Xorg.wrap) with a very large -maxclients will tell you which values it supports for that option:

/usr/lib/xorg/Xorg -maxclients 1000000000
...
(EE) maxclients must be one of 64, 128, 256, 512, 1024 or 2048

The number of clients actually connected to a display could be obtained via the X-Resource extension; xrestop is an app making use of it to display the X11 clients and the resources they're using in a top-like manner.

  • 3
    See [this change](https://cgit.freedesktop.org/xorg/xserver/commit/?id=d206c240c0b85c4da44f073d6e9a692afb6b96d2) and https://bugs.freedesktop.org/show_bug.cgi?id=9209 – Stéphane Chazelas Apr 26 '19 at 22:03
  • Thanks. (1) How can I change the value for `MaxClients`? (2) How can I find out how many x clients are running? `xlsclients` only reports 30 processes. – Tim Apr 26 '19 at 22:13
  • 1
    You can change it with the `-maxclients` option when starting the Xserver. –  Apr 26 '19 at 22:15
  • Do I have to close all the windows and kill all the X clients, before I can restart X server? – Tim Apr 26 '19 at 22:19
  • 1
    Yes, restarting the Xserver will kill all clients. As to how reliable xlsclients is, we already had that discussion, I'll let you find the link ;-) –  Apr 26 '19 at 22:21
  • @Tim yes, `xrestop` which is using the `X-Resource` extension will tell you how many clients there are and what resources they're using. –  Apr 26 '19 at 22:40
  • Thanks. How can I configure the max limit when X server is started automatically during OS startup? – Tim Apr 26 '19 at 22:50
  • 1
    That depends on what display manager you're using -- eg. for `xdm` is in `/etc/X11/xdm/Xservers`, for `lightdm` is `xserver-command` in `/etc/lightdm/lightdm.conf`, etc. You can also configure it in `/etc/X11/xorg.conf`, see the very 1st paragraph from my answer. –  Apr 26 '19 at 22:53
  • `printf 'Section "ServerFlags"\n\tOption "MaxClients" "512"\nEndSection' > /etc /X11/xorg.conf.d/99-maxclients.conf` (as root) may do it, irrespective of your dm. –  Apr 27 '19 at 20:55
  • Thanks. How can I find out the current limit on the number of X clients? My Lubuntu 18.04 doesn't have a file named `osinit.c`. – Tim Jul 05 '19 at 12:18
  • 1
    @Tim trying to run `Xorg` with a very large `-maxclients` will tell the values it actually supports for that option -- if you're doing that as a regular user, you'll have to use the real `Xorg` binary, not the "Only console users" wrapper. Also, you can cat the exact sources which were used to build the Xserver on your "Lubuntu" (including but not limited to the `xorg-server-*/os/osinit.c` file) with `apt-get source xserver-xorg-core`. –  Aug 06 '19 at 07:45
  • Thanks. I will follow up some time – Tim Aug 06 '19 at 22:20
  • Thanks. I created `/X11/xorg.conf.d/99-maxclients.conf` in July, and didn't restart my Lubuntu until recently. I just remember it, and it seems that I could create slightly more X clients than before, but I don't know a way to verify that yet. – Tim Nov 20 '19 at 13:21