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 766156 - X crashes when removing secondary monitor
X crashes when removing secondary monitor
Status: RESOLVED FIXED
Product: metacity
Classification: Other
Component: X extension
2.34.x
Other Linux
: Normal major
: ---
Assigned To: Metacity maintainers list
Metacity maintainers list
Depends on:
Blocks:
 
 
Reported: 2016-05-09 04:09 UTC by chander
Modified: 2016-06-29 14:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Metacity crash logs (1.70 MB, text/plain)
2016-05-09 05:10 UTC, chander
  Details
patch for testing (2.25 KB, patch)
2016-05-09 09:38 UTC, Alberts Muktupāvels
none Details | Review
metacity verbose logs with added warning and prints to track flow (829.89 KB, text/plain)
2016-05-10 03:14 UTC, chander
  Details
test (2.29 KB, patch)
2016-05-12 08:27 UTC, Alberts Muktupāvels
none Details | Review
constraints: validate fullscreen monitors before using them (1.56 KB, patch)
2016-05-12 16:31 UTC, Alberts Muktupāvels
committed Details | Review

Description chander 2016-05-09 04:09:39 UTC
Hi I have installed Linux Citrix reciever. 
I have opened one XenApp using selfservice. I have two monitors attached. 
Xinerma extensions are enabled.

If i remove the secondary monitor on the fly the X crashes.
Comment 1 chander 2016-05-09 05:10:13 UTC
Created attachment 327489 [details]
Metacity crash logs
Comment 2 Alberts Muktupāvels 2016-05-09 07:32:20 UTC
What do you expect from Metacity when X crashes? I guess you loose whole session when that happens not only Metacity, right?
Comment 3 chander 2016-05-09 08:13:56 UTC
(In reply to Alberts Muktupāvels from comment #2)
> What do you expect from Metacity when X crashes? I guess you loose whole
> session when that happens not only Metacity, right?

Hi Alberts, 
Thanks for the reply.

It appears as if crash in X originates from some miscalculation in metacity either when its applying the constraints on Citrix desktop window or during calculation of new placement for window.

Metacity logs show some large garbage value for offset and height/width of a window.
Comment 4 Alberts Muktupāvels 2016-05-09 08:33:00 UTC
Have you tried other window manager in your session? mutter, compiz, marco? Does it crash only with metacity?
Comment 5 chander 2016-05-09 08:46:08 UTC
Its working with on X86
Compiz 0.9.7.12.

My Environment is:
Arm, Yocto poky_dizzy_1.7.1

also it works with metacity when xinerama is disabled from build options of metacity
Comment 6 Alberts Muktupāvels 2016-05-09 09:20:18 UTC
Is there any window fullscreen when you remove secondary monitor?
Comment 7 Alberts Muktupāvels 2016-05-09 09:38:20 UTC
Created attachment 327500 [details] [review]
patch for testing

Can you rebuild metacity with this patch and post output you get? Maybe that will help to find why entire_xinerama is so big...
Comment 8 chander 2016-05-09 11:16:24 UTC
Yes..there is a full screen window when we remove the secondary monitor.
We have added the patch created by you along with few more logs to track down the root cause.
Will share the result with you.
Comment 9 chander 2016-05-10 03:14:55 UTC
Created attachment 327554 [details]
metacity verbose logs with added warning and prints to track flow

Sharing the logs from metacity with your patch.
It can be seen on Line 15059 that a big offset is received during calculation of union of rects for entire xinerama. Any Idea whats the idea behind checking for 4 full screen monitor info?

Another(or related) potential cause is rect for window recieved in setup_constraint_info() where xineram's offset is 0,0 but windows offset is 1920,0.

checking more logs to track it down. Will keep you updated.
Comment 10 chander 2016-05-11 08:49:36 UTC
From logs and some experimentation problem seems to be this:

When both monitors are connected, meta_window_update_fullscreen_monitors( ) is called for Citrix's Desktop window with values for 'left','top' and 'bottom' as 0 and value of 'right' as 1. these values are assigned to 
window->fullscreen_monitors[] .

These values are used as index for monitors (0 and 1 for two available monitors) in screen->xinerama_infos[] for calculation union of monitor rectangles in setup_constraint_info() function.

When we disconnect secondary monitor, xinerama_infos is allocated only for single monitor (index 0) but after disconnection meta_window_update_fullscreen_monitors( ) is not called and hence window->fullscreen_monitors[] has the stale values which when used as index for xinerama_infos[] results in invalid memory access corresponding to index=1 and gets garbage value.

Placing below condition before meta_rectangle_union() in setup_constraint_info() avoids the above situation and consequently there is no crash.

if(monitor >= window->screen->n_xinerama_infos)
{
  continue;
}

Trying to find possible reason for meta_window_update_fullscreen_monitors( ) not being called after disconnection.
Comment 11 Alberts Muktupāvels 2016-05-12 08:27:12 UTC
Created attachment 327677 [details] [review]
test

Does this patch change anything?
Comment 12 chander 2016-05-12 11:20:44 UTC
It still crashes with this :-(
Comment 13 Alberts Muktupāvels 2016-05-12 14:36:30 UTC
Can you check if meta_window_update_fullscreen_monitors functions is called when you disconnect secondary monitor? With your if (to check if monitor is valid) so it does not crash...

If it is still not called then it is also bug in application. From specification:
"In the event of a change in monitor configuration, the application is responsible for re-computing the monitors on which it wants to appear."

See:
https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472531472

Still metacity should not crash... Probably metacity should remove this info as it is most likely not valid. But I am worried if application can send client message before we clear this list...
Comment 14 Alberts Muktupāvels 2016-05-12 16:31:58 UTC
Created attachment 327726 [details] [review]
constraints: validate fullscreen monitors before using them
Comment 15 Alberts Muktupāvels 2016-06-25 10:58:06 UTC
Did you test last patch?
Comment 16 chander 2016-06-29 11:23:38 UTC
Yes ..validating fullscreen monitor avoids the crash and did solve our issue.
Thanks a lot for your help