提交 933ad860 编写于 作者: P Pavel Hrdina

tests: fix deadlock in eventtest

There is a race deadlock in eventtest after the recent rewrite to drop
GNULIB from libvirt code base.

The issue happens when the callbacks testPipeReader() or testTimer()
are called before waitEvents() starts waiting on `eventThreadCond`.
It will never happen because the callbacks are already done and there
is nothing that will signal the condition again.
Reported-by: NPeter Krempa <pkrempa@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 5e35d4a5
......@@ -43,6 +43,7 @@ VIR_LOG_INIT("tests.eventtest");
static pthread_mutex_t eventThreadMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t eventThreadCond = PTHREAD_COND_INITIALIZER;
static bool eventThreadSignaled;
static struct handleInfo {
int pipeFD[2];
......@@ -138,8 +139,9 @@ testPipeReader(int watch, int fd, int events, void *data)
virEventRemoveHandle(info->delete);
cleanup:
pthread_mutex_unlock(&eventThreadMutex);
pthread_cond_signal(&eventThreadCond);
eventThreadSignaled = true;
pthread_mutex_unlock(&eventThreadMutex);
}
......@@ -164,8 +166,9 @@ testTimer(int timer, void *data)
virEventRemoveTimeout(info->delete);
cleanup:
pthread_mutex_unlock(&eventThreadMutex);
pthread_cond_signal(&eventThreadCond);
eventThreadSignaled = true;
pthread_mutex_unlock(&eventThreadMutex);
}
G_GNUC_NORETURN static void *eventThreadLoop(void *data G_GNUC_UNUSED) {
......@@ -185,7 +188,10 @@ waitEvents(int nhandle, int ntimer)
VIR_DEBUG("Wait events nhandle %d ntimer %d",
nhandle, ntimer);
while (ngothandle != nhandle || ngottimer != ntimer) {
pthread_cond_wait(&eventThreadCond, &eventThreadMutex);
while (!eventThreadSignaled)
pthread_cond_wait(&eventThreadCond, &eventThreadMutex);
eventThreadSignaled = false;
ngothandle = ngottimer = 0;
for (i = 0; i < NUM_FDS; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册