After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 697673 - Apps should connect only once when using Wayland
Apps should connect only once when using Wayland
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Wayland
3.8.x
Other Linux
: High critical
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-04-09 23:08 UTC by Tiago Vignatti
Modified: 2013-04-19 13:07 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tiago Vignatti 2013-04-09 23:08:21 UTC
GTK+ is connecting twice every time one application is starting. It checks whether a connection to the default display server is possible during initialisation and fail otherwise:

https://bugzilla.gnome.org/show_bug.cgi?id=694465

GTK+ should be able to use the same access control style as toytoolkit clients for example, using WAYLAND_SOCKET probably.
Comment 1 Chris Cummins 2013-04-11 10:36:29 UTC
Hi Tiago, I took a look at this but couldn't find much room for improvement. It
wouldn't be possible for GtkWaylandDisplayManager to keep the display connection
that is opened during initialization, as this would cause a leak in the case
where the client doesn't intend to use the default display but instead opens a
different display after initialization. WAYLAND_SOCKET is handled transparently
by wl_display_connect() the same way in GTK+ as toytoolkit clients.
Comment 2 Rob Bradford 2013-04-12 13:26:38 UTC
Closing on Chris's behalf.
Comment 3 Kristian Høgsberg 2013-04-12 16:09:50 UTC
I think it should be possible for GTK+ to do better.  Surely some kind of two-phase approach where we try all connections and keep them around, then pick one and close all others.  Or in case GDK_BACKEND is set to wayland, don't try other connections at all?  Lastly, it's also not necessary to try to connect to see if it's possible if WAYLAND_SOCKET is set - if it is, we already have a connection.
Comment 4 Kristian Høgsberg 2013-04-12 16:39:36 UTC
In case that comment was unclear, there are three suggestions on how to avoid the double connect:

 1) Try to open all types of displays, keep connections open, decide which one to use, close all others.  Instead of the current open all, close all, decide which one to use, open that one again.

 2) If GDK_BACKEND is set, skip the first step of opening all types of display and just open the one we're asked to open; fail if that doesn't work.

 3) WAYLAND_SOCKET is typically used when a compositor launches a client and provides one end of a socketpair as the connection fd to the client.  In that case, there's no reason to try to connect, since we know it will always succeed.
Comment 5 Rob Bradford 2013-04-12 17:51:13 UTC
For 3.) I just pushed:

commit bff5b2ae3ee51e83564ead19f410be9ff0c00326
Author: Rob Bradford <rob@linux.intel.com>
Date:   Fri Apr 12 18:39:20 2013 +0100

    wayland: Don't "probe" for a Wayland compositor if started from compositor
    
    In the case that the client is started directly by the compositor the
    WAYLAND_SOCKET environment variable is set containing the fd to use that was
    created by a socketpair.
    
    This environment variable is consumed by a call to wl_display_connect so a
    second call will not take advantage of it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697673
Comment 6 Rob Bradford 2013-04-12 18:09:16 UTC
For 2.) if GDK_BACKEND is set only that backend (or backends since it can be a , separated list) will actually be tried.

If that isn't set the application's defined allowable backend set is used which defaults to "*" for all backends.

But GDK_BACKEND always takes precedence!

For 1.) as soon as we find a working backend we use that type - but yes end up opening the connection closing it and then reopening it

The code is a bit complex but i'm confident this is how it works.

I agree that we could definitely try and reuse the "probe" connection for the real one - and i'll work on patch to that effect.
Comment 7 Rob Bradford 2013-04-19 13:07:01 UTC
commit 524ce7f88e26a498c43729f99fda564f5e222582
Author: Rob Bradford <rob@linux.intel.com>
Date:   Fri Apr 19 13:59:58 2013 +0100

    wayland: Cache the discovery connection and reuse if possible
    
    This will prevent us opening, closing and reopening the same display
    connection in the majority of cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694465