Bug 27595 - xcb_io.c: synchronization problem
xcb_io.c: synchronization problem
Status: VERIFIED FIXED
Product: xorg
Classification: Unclassified
Component: Lib/Xlib
git
Other All
: medium normal
Assigned To: Xorg Project Team
Xorg Project Team
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-12 00:44 UTC by Rami Ylimaki
Modified: 2010-04-13 03:27 UTC (History)
2 users (show)

See Also:


Attachments
test case (1.41 KB, text/plain)
2010-04-12 00:47 UTC, Rami Ylimaki
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rami Ylimaki 2010-04-12 00:44:57 UTC
This problem was first noticed at the beginning of year 2009 with XNEE. It seems that the problem has been worked around in XNEE but not fixed properly in Xlib. One source of confusion last year seems to be the problems with recording extension and therefore the problem probably wasn't linked to Xlib. You can reproduce this with older version of XNEE or with the attached test case.

Last time I checked, Xlib 1.1.5 didn't have this problem. Newer versions do and if I remember correctly --with-xcb is required even though I haven't checked that recently.

What you need to do is:

    ctrl_disp = XOpenDisplay(NULL);
    data_disp = XOpenDisplay(NULL);
    XSynchronize(ctrl_disp, True);
    XRecordQueryVersion(ctrl_disp, &major, &minor);
    rc = XRecordCreateContext (ctrl_disp, 0, &rcs, 1, &rr, 1);
    XRecordEnableContextAsync(data_disp, rc, event_callback, NULL);
    XFlush(data_disp);

The request to enable context will fail because it hasn't been created yet. In other words the request to create context hasn't been flushed to X server even though the display connection has been set as synchronous.

It seems that xcb_io.c:_XAllocID overrides the sync function with a private version. XRecordCreateContext calls XAllocID, which causes the SyncHandle at the end of the request to do nothing.
Comment 1 Rami Ylimaki 2010-04-12 00:47:42 UTC
Created attachment 34905 [details]
test case

Adding xcb@lists.freedesktop.org into CC.
Comment 2 Jamey Sharp 2010-04-12 11:37:51 UTC
Thanks for the test case! It made the bug pretty easy to track down. I've pushed a fix to libX11 git. It looks like this has indeed been broken in every XCB-enabled release of libX11 ever. Oops. ...I blame keithp. ;-)

After applying the fix, I found that the test program hangs in XCloseDisplay on the data_disp connection, waiting for the server to respond to an XSync. I had to insert "XRecordDisableContext (ctrl_disp, rc);" before that to get it to exit successfully. Is that expected? I'm not sure how Record is supposed to work.
Comment 3 Rami Ylimaki 2010-04-13 03:27:13 UTC
(In reply to comment #2)
> Thanks for the test case! It made the bug pretty easy to track down. I've
> pushed a fix to libX11 git. It looks like this has indeed been broken in every
> XCB-enabled release of libX11 ever. Oops. ...I blame keithp. ;-)
> 
> After applying the fix, I found that the test program hangs in XCloseDisplay on
> the data_disp connection, waiting for the server to respond to an XSync. I had
> to insert "XRecordDisableContext (ctrl_disp, rc);" before that to get it to
> exit successfully. Is that expected? I'm not sure how Record is supposed to
> work.

Thanks for fixing it so quickly.

You are right, the test case had a bug and XRecordDisableContext call should be there. The original test case had that call but I removed it when trying to minimize it.

It's also possible to make the test case work without XRecordDisableContext by executing
    XCloseDisplay (ctrl_disp);
    XCloseDisplay (data_disp);
instead of
    XCloseDisplay (data_disp);
    XCloseDisplay (ctrl_disp);
at the end of the case.