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 691095 - Metacity can map wrong window if XID is reused on new connection (with fix)...
Metacity can map wrong window if XID is reused on new connection (with fix)...
Status: RESOLVED OBSOLETE
Product: metacity
Classification: Other
Component: general
2.34.x
Other Linux
: Normal normal
: ---
Assigned To: Metacity maintainers list
Metacity maintainers list
Depends on:
Blocks:
 
 
Reported: 2013-01-03 22:09 UTC by Alan Amaral
Modified: 2020-11-06 20:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch which avoids remapping a deleted window (3.07 KB, patch)
2013-01-03 22:12 UTC, Alan Amaral
none Details | Review

Description Alan Amaral 2013-01-03 22:09:14 UTC
I've found, and fixed, a race condition that was causing metacity to map a window which shouldn't have been mapped, in a fairly obscure, but possible, situtation.

In our system we have a custom monitor manager which handles automatic monitor hotplug detection and configuration, etc.  We also have an app which creates windows, one per monitor, each monitor handler utilizing its own X connection.

The bug we've seen is that if a laptop with no external monitor attached is suspended, then an external monitor is attached, and the system is resumed with the lid closed, the old monitor handler is destroyed, along with its window and X connection, a new monitor handler is created along with a new X connection and window, and sometimes our app window ends up mapped in front of our lock screen, when it shouldn't.

The exact cause is as follows:

Client 1 opens X connection for laptop monitor, creates window W, maps window W.

Xorg     creates the window and redirects the maprequest to metacity.

Metacity gets redirected maprequest from the X server and maps window W.

Client 1 destroys window W and disconnects from X server.

Client 2 opens X connection for external monitor, (and gets same XID for
         window as client 1), creates window W (without mapping it).

Metacity sees window W get destroyed and in display.c:event_callback it
         calls meta_window_free (line 1960).  meta_window_free cleans up
         its data structures, pushes an error trap and at line 1193 REMAPS(!)
         the newly destroyed window.  Apparently the developer relied on
         the fact that for a destroyed window the error trap would handle
         the BadWindow X error in this case, and rather than trying to
         avoid the error just lets it happen.  The reason for remapping
         the window seems to be because the same function (meta_window_free)
         is called when metacity is shutdown, so any windows mapped by
         clients end up mapped for the new window manager.

The problem is that in this case the BadWindow error doesn't happen.  Metacity has incorrectly mapped the NEW WINDOW from Client 2, which the client never asked to be mapped.

The fix for this seems to be to avoid doing the map if the window has been
destroyed.  I have a patch that does this, although there may be a better
way to handle it.  If I can get it to attach I'll do that, else I'll add it
as an additional comment. (don't ask me why my machine keeps deleting the attachment field when I hit Commit, I don't know...)
Comment 1 Alan Amaral 2013-01-03 22:12:07 UTC
Created attachment 232685 [details] [review]
patch which avoids remapping a deleted window
Comment 2 Alberts Muktupāvels 2017-09-29 23:24:43 UTC
(In reply to Alan Amaral from comment #0)
> Client 1 destroys window W and disconnects from X server.
> 
> Client 2 opens X connection for external monitor, (and gets same XID for
>          window as client 1), creates window W (without mapping it).
> 

Why would it get same xid? What is client 1 and client 2 in this case?
Comment 3 André Klapper 2020-11-06 20:06:44 UTC
bugzilla.gnome.org is being replaced by gitlab.gnome.org. We are closing all old bug reports in Bugzilla which have not seen updates for many years.

If you can still reproduce this issue in a currently supported version of GNOME (currently that would be 3.38), then please feel free to report it at https://gitlab.gnome.org/GNOME/metacity/-/issues/

Thank you for reporting this issue and we are sorry it could not be fixed.