Bug 16497

Summary: X11() hangs after updating to xorg-x11-server-Xort-1.15.0-36.elg.x86_64
Product: R Reporter: Leslie Boyd <lhb>
Component: GraphicsAssignee: Martyn Plummer <martyn.plummer>
Status: CLOSED FIXED    
Severity: normal CC: hjalti.sveinsson, holken, junksjb, maechler, mark.crossland, martyn.plummer, patrick.gendron, paulg, pd.mes, schanzle, svashisht, tcallawa
Priority: P3    
Version: R-devel (trunk)   
Hardware: Other   
OS: Linux   
Attachments: Disable backing store in X11 window
Wait for MapNotify event while intializing window

Description Leslie Boyd 2015-08-04 21:21:31 UTC
From within R, this command X11() will grab the upper left corner of the screen and hang. It is possible to move the window. It is not possible to close it.

Downgrading the patch to 1.15.0-26.el6_6.x86_64 will allow the function to work again.
Comment 1 Brian Ripley 2015-08-12 15:25:27 UTC
*** Bug 16499 has been marked as a duplicate of this bug. ***
Comment 2 Brian Ripley 2015-08-12 15:30:05 UTC
Why is this a bug in R?  As described it is an X server bug which we cannot fix.

I guess 'elg' is el6, hence RHEL 6.  But please report the full sessionInfo() in future.

In any case 1.15.0 is rather old: e.g. Fedora 21 has 1.16.3.
Comment 3 Simon B 2015-09-02 09:19:56 UTC
(In reply to Brian Ripley from comment #2)
> Why is this a bug in R?  As described it is an X server bug which we cannot
> fix.
> 
> I guess 'elg' is el6, hence RHEL 6.  But please report the full
> sessionInfo() in future.
> 
> In any case 1.15.0 is rather old: e.g. Fedora 21 has 1.16.3.

Well while it is true that 1.15 is rather old this is what our "enterprise" linux provider gives us and we have not much say in the matter.  As Red Hat does not support R we rely on the good will of the maintainers of R to help us out in these situations.  As an organisation this issue is causing us quite a lot of pain.

To help, below are two sets of info, the first the current broken R/Xorg combo followed by the last combo that worked.  We have 2 R versions installed both dont work.

Thank you.

### BROKEN SYSTEM ###
> Xorg -version 
X.Org X Server 1.15.0
Release Date: 2013-12-27
X Protocol Version 11, Revision 0
Build Operating System: x86-022 2.6.18-404.el5 Current Operating System: Linux eld426 2.6.32-573.1.1.el6.x86_64 #1 SMP Tue Jul 14 02:46:51 EDT 2015 x86_64 Kernel command line: ro root=/dev/mapper/vgdesktop-slash rd_MD_UUID=2c089a6b:9c2cd1eb:de64b7cf:f0aae67f rd_LVM_LV=vgdesktop/slash rd_MD_UUID=7e7f1ab7:7778f45d:f6a1101f:5e8c1e97 rd_NO_LUKS rd_NO_DM LANG=C SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk crashkernel=129M@0M rhgb quiet rdblacklist=nouveau vga=792 reboot=bios intel_idle.max_cstate=0 processor.max_cstate=1 Build Date: 21 May 2015  10:10:09AM Build ID: xorg-x11-server 1.15.0-36.el6 Current version of pixman: 0.32.4
	Before reporting problems, check https://www.redhat.com/apps/support/
	to make sure that you have the latest version.

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-redhat-linux-gnu (64-bit)
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Client release 6.7 (Santiago)

### WORKING SYSTEM ###
> Xorg -version 
X.Org X Server 1.15.0
Release Date: 2013-12-27
X Protocol Version 11, Revision 0
Build Operating System: x86-027 2.6.18-400.1.1.el5 Current Operating System: Linux eld139 2.6.32-504.16.2.el6.x86_64 #1 SMP Tue Mar 10 17:01:00 EDT 2015 x86_64 Kernel command line: ro root=/dev/mapper/vgdesktop-slash rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=uk LANG=C rd_LVM_LV=vgdesktop/slash SYSFONT=latarcyrheb-sun16 rhgb crashkernel=129M@0M rd_MD_UUID=700638ec:2c0e8707:cc3dadcf:07c80610 rd_MD_UUID=bc64fea5:9f2d52c5:7a1159ba:3897d914 quiet rd_NO_DM rdblacklist=nouveau vga=792 reboot=bios intel_idle.max_cstate=0 processor.max_cstate=1 Build Date: 06 February 2015  12:21:48AM Build ID: xorg-x11-server 1.15.0-26.el6_6 Current version of pixman: 0.32.4
                Before reporting problems, check https://www.redhat.com/apps/support/
                to make sure that you have the latest version.

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-redhat-linux-gnu (64-bit)
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Client release 6.7 (Santiago)
Comment 4 Martyn Plummer 2015-09-02 14:28:52 UTC
Red Hat may not officially support R on RHEL, but RPMs are available via the EPEL project, e.g:
https://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/R.html

For Redhat-specific issues you may wish to try the mailing list R-SIG-Fedora@r-project.org. Tom Callaway, who maintains the Fedora R binaries, is a subscriber.
Comment 5 Siteshwar Vashisht 2015-09-17 11:34:54 UTC
This regression is introduced by below change :

* Wed Feb 25 2015 Adam Jackson <ajax@redhat.com> 1.15.0-32
- Fix backing store's Always mode

If backing store is enabled Xorg server will not send Expose events to the application. X11 module explicity enables backing store at line 1480 in modules/X11/devX11.c :

1478     attributes.background_pixel = whitepixel;
1479     attributes.border_pixel = blackpixel;
1480     attributes.backing_store = Always;
1481     attributes.event_mask = ButtonPressMask


but it waits for Expose event at start up and interpreter is left looping at line 1703-1704:

1693         if(alreadyCreated == 0) {
1694             XSelectInput(display, xd->window,
1695                          ExposureMask | ButtonPressMask | StructureNotifyMask
1696                          | ButtonReleaseMask | ButtonMotionMask
1697                          | PointerMotionHintMask | KeyPressMask);
1698             XMapWindow(display, xd->window);
1699             XSync(display, 0);
1700 
1701             /* Gobble expose events */
1702 
1703             while ( XPeekEvent(display, &event),
1704                     !XCheckTypedEvent(display, Expose, &event))
1705                 ;
1706             /* XNextEvent(display, &event);
1707                if (event.xany.type == Expose) {
1708                while (event.xexpose.count)
1709                XNextEvent(display, &event);
1710                }
1711             */
1712         }

This is a bug in the X11 module. It should not use backing store if it is relying on Expose events.
Comment 6 Siteshwar Vashisht 2015-09-17 11:39:32 UTC
Created attachment 1911 [details]
Disable backing store in X11 window

Xorg server will not generate Expose events if backing store is enabled. Since implementation of this X11 module relies on Expose events, we should explicitly disable backing store in X11 window.
Comment 7 Siteshwar Vashisht 2015-09-17 11:44:51 UTC
Created attachment 1912 [details]
Wait for MapNotify event while intializing window

Instead of Expose event we should wait for MapNotify event at startup (even when backing store is disabled).
Comment 8 Peter Dalgaard 2015-09-17 13:54:38 UTC
*** Bug 16535 has been marked as a duplicate of this bug. ***
Comment 9 Peter Dalgaard 2015-09-17 14:00:22 UTC
....and, of course, thanks for digging into this!
Comment 10 Tom Callaway 2015-09-28 14:12:15 UTC
Peter, do those patches seem correct on your end? I don't mind pushing out an update for Fedora and RHEL with them applied, but I want to make sure they're going to end up in a later release first.
Comment 11 Peter Dalgaard 2015-09-28 15:31:47 UTC
Tom, the patch _looked_ sane, but I think someone more expert than me should make the call. I can only test on OSX at this time.

It wouldn't surprise me if whoever coded this was unaware of the finer distinctions between MapNotify and Expose, but ca we be sure that the former is always generated for all X servers?

I assume it is only the 2nd patch that need to be applied. Turning backing store off, sounds undesirable.

-pd
Comment 12 Tom Callaway 2015-09-28 15:34:34 UTC
That seems right to me as well, but I am also not an X expert by any definition.
Comment 13 paulg 2015-10-06 17:38:56 UTC
This is also a problem for the command plot()
Comment 14 paulg 2015-10-06 17:40:22 UTC
Bug reported on CentOS Bug tracker. 

https://bugs.centos.org/view.php?id=9562
Comment 15 gendrop 2015-10-07 15:36:38 UTC
Just an addition to mention that I have had this bug not only freeze the X11() window but occasionally crash the X server:

[  5552.124] (EE) Backtrace:
[  5552.124] (EE) 0: /usr/bin/Xorg (xorg_backtrace+0x51) [0x5ab521]
[  5552.124] (EE) 1: /usr/bin/Xorg (0x400000+0x1af919) [0x5af919]
[  5552.124] (EE) 2: /lib64/libpthread.so.0 (0x395c400000+0xf790) [0x395c40f790]
[  5552.124] (EE) 3: /usr/bin/Xorg (miHandleValidateExposures+0x29) [0x5a4829]
[  5552.124] (EE) 4: /usr/bin/Xorg (0x400000+0x654e6) [0x4654e6]
[  5552.124] (EE) 5: /usr/bin/Xorg (ConfigureWindow+0xb4a) [0x467d2a]
[  5552.124] (EE) 6: /usr/bin/Xorg (0x400000+0x37034) [0x437034]
[  5552.124] (EE) 7: /usr/bin/Xorg (0x400000+0x38ee6) [0x438ee6]
[  5552.124] (EE) 8: /usr/bin/Xorg (0x400000+0x3c94a) [0x43c94a]
[  5552.124] (EE) 9: /lib64/libc.so.6 (__libc_start_main+0xfd) [0x395bc1ed5d]
[  5552.124] (EE) 10: /usr/bin/Xorg (0x400000+0x269c9) [0x4269c9]
[  5552.124] (EE) 
[  5552.125] (EE) Segmentation fault at address 0x0
[  5552.125] (EE) 
Fatal server error:
[  5552.125] (EE) Caught signal 11 (Segmentation fault). Server aborting
[  5552.125] (EE) 
[  5552.125] (EE) 
P
Comment 16 holken 2015-10-14 12:45:51 UTC
Confirm that patches are working on R 3.2.2 and Red Hat Enterprise Linux Workstation release 6.7 (Santiago) x86_64
Comment 17 schanzle 2015-10-20 16:20:13 UTC
Would be great and appreciated to have the patches integrated into the EPEL packages for el6.  

Should we continue to hold back the patches due to long-term fears, or just fix the problem so R is useful again?
Comment 18 Tom Callaway 2015-10-23 15:14:51 UTC
I've kicked off builds of R with both patches applied for all Fedora and EL targets. Barring any surprises, they'll be in updates-testing soon.
Comment 19 Martin Maechler 2015-10-27 13:01:09 UTC
(In reply to Tom Callaway from comment #18)
> I've kicked off builds of R with both patches applied for all Fedora and EL
> targets. Barring any surprises, they'll be in updates-testing soon.

Thank you, Tom.

I really think we (R core team) should also apply (some of) these patches to the R sources.

Peter Dalgaard ('pd') had asked/suggested (in 'Comment 11') 

 | I assume it is only the 2nd patch that need to be applied. Turning
 | backing store off, sounds undesirable. 

and I'd agree with him just from code reading that it does seem sufficient to
apply the 2nd patch ('id=1912') alone to fix the problem, and the first patch is not necessary (and may be performance degrading in some cases).

Can you please clarify?
Comment 20 Martyn Plummer 2015-11-05 12:38:02 UTC
I have added the second patch (wait for MapNotify on initialization) to R-devel. Leaving the bug open for now in case there are further reports.
Comment 21 Martyn Plummer 2017-09-08 12:15:19 UTC
I finally applied the first patch (Disable backing store in X11 window). We found graphics anomalies with Xwayland on both Debian buster and Fedora 26 when a buffered X11 device also used the Xlib backing store.

This patch has been applied to Red Hat binary distributions of R for some time, so I am confident it will not cause any issues and have ported it straight to R 3.4.1 patched.