From nobody Thu Apr 25 14:13:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580991767127693.9287988045513; Thu, 6 Feb 2020 04:22:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-yZ_8rHIcMFKV3_neAMP1yA-1; Thu, 06 Feb 2020 07:22:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BEC51005F73; Thu, 6 Feb 2020 12:22:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2325790E4; Thu, 6 Feb 2020 12:22:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AD4E5866A5; Thu, 6 Feb 2020 12:22:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 016CMWCw019550 for ; Thu, 6 Feb 2020 07:22:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id C889F5C3F8; Thu, 6 Feb 2020 12:22:32 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.43.2.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51D195C1D8 for ; Thu, 6 Feb 2020 12:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580991765; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NNY/6FxrDJ8njRV6Zo1hfIqrmfHZt06Y3izycDwi30w=; b=KJxGUUawLTiKuEu00wZI8yosr0NrcpAJ0rsydVkbgVTnm6fdeixZIHLnUbgP6V0yXNzArO LhocW0gJtdJRCNTzETRd329PS7pZboefT7ypUOyLzKZB9bqrXhNPrFV2EY8vK81Jvqa1XN MAzjnvurZ0Z6un4VCXswGV/W1GZaalQ= From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH] tests: fix deadlock in eventtest Date: Thu, 6 Feb 2020 13:22:28 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: yZ_8rHIcMFKV3_neAMP1yA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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: Peter Krempa Signed-off-by: Pavel Hrdina Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- tests/eventtest.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/eventtest.c b/tests/eventtest.c index 9855b578fb..fc814922f2 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -43,6 +43,7 @@ VIR_LOG_INIT("tests.eventtest"); =20 static pthread_mutex_t eventThreadMutex =3D PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t eventThreadCond =3D PTHREAD_COND_INITIALIZER; +static bool eventThreadSignaled; =20 static struct handleInfo { int pipeFD[2]; @@ -138,8 +139,9 @@ testPipeReader(int watch, int fd, int events, void *dat= a) virEventRemoveHandle(info->delete); =20 cleanup: - pthread_mutex_unlock(&eventThreadMutex); pthread_cond_signal(&eventThreadCond); + eventThreadSignaled =3D true; + pthread_mutex_unlock(&eventThreadMutex); } =20 =20 @@ -164,8 +166,9 @@ testTimer(int timer, void *data) virEventRemoveTimeout(info->delete); =20 cleanup: - pthread_mutex_unlock(&eventThreadMutex); pthread_cond_signal(&eventThreadCond); + eventThreadSignaled =3D true; + pthread_mutex_unlock(&eventThreadMutex); } =20 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 !=3D nhandle || ngottimer !=3D ntimer) { - pthread_cond_wait(&eventThreadCond, &eventThreadMutex); + while (!eventThreadSignaled) + pthread_cond_wait(&eventThreadCond, &eventThreadMutex); + + eventThreadSignaled =3D 0; =20 ngothandle =3D ngottimer =3D 0; for (i =3D 0; i < NUM_FDS; i++) { --=20 2.24.1