wayland/tests
Andrew Wedgbury 74df22befe test: Add test showing blocking problem when updating timers
I've noticed a blocking problem in Wayland's event-loop code when updating
timer event sources. The problem occurs if you update the timer at a point
after is has expired, but before it has been dispatched, i.e. from an event
callback that happens during the same epoll wakeup.

When the timer is subsequently dispatched, wl_event_source_timer_dispatch
blocks for the duration of the new timeout in its call to read() from the
timer fd (which is the expected behaviour according to the man page for
timerfd_settime).

This isn't too uncommon a scenario - for example, a socket with an associated
timeout timer. You'd typically want to update the timer when reading from the
socket. This is how I noticed the issue, since I was setting a timeout of
1 minute, and saw my server blocking for this duration!

The following patch adds a (currently failing) test case to Wayland's
event-loop-test.c. It demonstrates the problem using two timers, which are
set to expire at the same time. The first timer to receive its expiry
callback updates the other timer with a much larger timeout, which then
causes the test to block for this timeout before calling the second timer's
callback.

As for a fix, I'm not so sure (which is why I thought I'd post the failing
test case first to show what I mean). I notice that it doesn't actually do
anything with the value read from the timerfd socket, which gives the number
of times the timer expired since the last read, or when the timer was last
updated (which blocks if the timer hasn't yet expired). I believe this value
should always read as 1 anyway, since we don't use periodic timers.

A simple fix would be to use the TFD_NONBLOCK option when creating the
timerfd, ensuring that the read call won't block. We'd then have to ignore
the case when the read returns EAGAIN.
2014-04-25 14:08:31 -07:00
..
array-test.c array-test: assert wl_array_add result is not NULL 2014-01-15 10:46:08 -08:00
client-test.c server: Make wl_object and wl_resource opaque structs 2013-07-02 15:52:47 -04:00
connection-test.c connection: Don't write past the end of the connection buffer 2014-04-21 14:51:42 -07:00
display-test.c server: Make wl_object and wl_resource opaque structs 2013-07-02 15:52:47 -04:00
event-loop-test.c test: Add test showing blocking problem when updating timers 2014-04-25 14:08:31 -07:00
exec-fd-leak-checker.c tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00
fixed-benchmark.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
fixed-test.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
list-test.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
map-test.c Update tests for wl_map changes and add a map_flags test 2013-06-05 17:55:14 -04:00
os-wrappers-test.c os-wrappers-test: assert closure is not NULL before invoking it 2014-01-15 10:46:08 -08:00
queue-test.c queue-test: assert non-NULL return values 2014-01-15 10:46:08 -08:00
resources-test.c resources-test: Don't send invalid event 2014-01-20 15:07:55 -08:00
sanity-test.c tests: ensure sanity leak check tests pass when leak checks are disabled. 2012-08-29 14:10:24 -04:00
signal-test.c tests: add unit tests for wl_signal 2013-09-21 11:37:38 -07:00
socket-test.c tests: Quiet warning 2012-08-29 14:12:11 -04:00
test-helpers.c tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00
test-runner.c tests: extended message when leak in test is detected 2013-09-21 11:36:33 -07:00
test-runner.h tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00