Commit 406afe4b authored by Michel Dänzer's avatar Michel Dänzer Committed by Michel Dänzer

poll_for_response: Call poll_for_event again if xcb_poll_for_reply fails

If xcb_poll_for_reply fails to find a reply, poll_for_response would
always return NULL. However, xcb_poll_for_reply may have read events
from the display connection while looking for a reply. In that case,
returning NULL from poll_for_response is wrong and can result in the
client hanging, e.g. because it returns to waiting for the display
connection file descriptor becoming readable after XPending incorrectly
returned 0 pending events.

The solution is to call poll_for_event again after xcb_poll_for_reply
returned 0. This will return the first of any events read by

Fixes issue #79.
Reported-by: yshui's avatarYuxuan Shui <>
Bugzilla: Adam Jackson's avatarAdam Jackson <>
parent d0416863
......@@ -273,10 +273,19 @@ static xcb_generic_reply_t *poll_for_response(Display *dpy)
PendingRequest *req;
while(!(response = poll_for_event(dpy)) &&
(req = dpy->xcb->pending_requests) &&
!req->reply_waiter &&
xcb_poll_for_reply64(dpy->xcb->connection, req->sequence, &response, &error))
uint64_t request = X_DPY_GET_REQUEST(dpy);
uint64_t request;
if(!xcb_poll_for_reply64(dpy->xcb->connection, req->sequence,
&response, &error)) {
/* xcb_poll_for_reply64 may have read events even if
* there is no reply. */
response = poll_for_event(dpy);
request = X_DPY_GET_REQUEST(dpy);
if(XLIB_SEQUENCE_COMPARE(req->sequence, >, request))
throw_thread_fail_assert("Unknown sequence number "
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment