kiran-authentication-devices/0004-fix-mf-iristar-driver-when-the-iris-face-integrated-.patch

101 lines
4.5 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 444f3d097fa42fbfde53004ffe0404bb31313bac Mon Sep 17 00:00:00 2001
From: luoqing <luoqing@kylinsec.com.cn>
Date: Tue, 16 Jan 2024 11:57:08 +0800
Subject: [PATCH 4/6] fix(mf-iristar-driver):when the iris face integrated
device is removed, the memory cannot be released and the process is
blocked.When the face iris device object is removed, restart the service to
release resources
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 虹膜人脸一体设备在拔出时无法释放内存并且会阻塞进程,当释放人脸虹膜设备对象时,如果当前设备已经被拔出了,就重启服务,释放资源。
Related #25243
---
.../multi-function/mf-iristar-driver.cpp | 41 +++++++++++++++----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/src/driver/multi-function/mf-iristar-driver.cpp b/src/driver/multi-function/mf-iristar-driver.cpp
index 7c11d43..f65af2d 100644
--- a/src/driver/multi-function/mf-iristar-driver.cpp
+++ b/src/driver/multi-function/mf-iristar-driver.cpp
@@ -17,12 +17,14 @@
#include <qt5-log-i.h>
#include <sys/time.h>
#include <QCryptographicHash>
+#include <QProcess>
#include <functional>
#include <iostream>
#include "auth-enum.h"
#include "auth_device_adaptor.h"
#include "driver/driver-factory.h"
#include "feature-db.h"
+#include "utils.h"
namespace Kiran
{
@@ -46,6 +48,7 @@ std::function<Ret(Params...)> Callback<Ret(Params...)>::func;
#define IRIS_IS_DRIVER_LIB "libirs_sdk2.so"
#define IRIS_IS_STARTUP_CONFIG_PATH "/etc/kiran-authentication-devices-sdk/iristar/config/sdkcfg.ini"
+#define SYSTEMCTL_RESTART_SERVICE "systemctl restart kiran-authentication-devices.service"
#define IRIS_FEATURE_LEN 512 // 单个虹膜特征数据长度
#define FACE_FEATURE_LEN 2048 // 单个人脸特征数据长度
@@ -122,13 +125,18 @@ MFIriStarDriver::MFIriStarDriver(QObject *parent) : Driver{parent}
MFIriStarDriver::~MFIriStarDriver()
{
- if (m_driverLib->isLoaded && m_irsHandle)
- {
- bool enable = false;
- m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_IRIS_LIGHT, &enable, sizeof(enable));
- m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_CANCEL_OPR, NULL, 0); // 停止当前正在进行的流程
- m_driverLib->IRS_releaseInstance(m_irsHandle);
- }
+ KLOG_DEBUG() << "destroy IriStar driver";
+ /*
+ if (m_driverLib->isLoaded && m_irsHandle )
+ {
+ KLOG_DEBUG() << "start release IriStar Instance";
+ bool enable = false;
+ m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_IRIS_LIGHT, &enable, sizeof(enable));
+ m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_CANCEL_OPR, NULL, 0); // 停止当前正在进行的流程
+ m_driverLib->IRS_releaseInstance(m_irsHandle);
+ KLOG_DEBUG() << "release IriStar Instance end";
+ }
+ */
if (m_libHandle)
{
@@ -137,6 +145,25 @@ MFIriStarDriver::~MFIriStarDriver()
}
m_driverLib.clear();
+
+ /**
+ * FIXME:
+ * 1、IriStart 设备不支持热插拔
+ * 当设备拔出后调用SDK中的IRS_releaseInstance释放资源IRS_releaseInstance会搜索设备如果没有搜索到设备将一直循环搜索设备导致进程卡死
+ * 如果设备突然被拔出则IRS_releaseInstance函数无效且一直无法释放资源造成内存泄漏
+ *
+ * 2、注意即使在设备存在的情况下调用IRS_releaseInstance 释放资源,也会失败
+ * 注意即使在设备存在的情况下调用IRS_releaseInstance 释放资源也会失败在IRS_releaseInstance函数中阻塞
+ * 查看堆栈,调用关系为 IRS_releaseInstance -> pthread_cond_destroy 发现最终阻塞在pthread_cond_destroy中
+ * 查阅资料pthread_cond_destroy 用来销毁条件变量但是销毁其他线程正在等待的cond将导致不确定行为并阻塞。
+ * 该设备驱动在运行过程中会创建非常多的线程由于设备SDK提供商对线程操作的不合理导致了阻塞。
+ *
+ * 由于不知道驱动SDK的源代码和具体线程操作逻辑此问题无法修复只能规避
+ * 因此,在释放对象时,暂时重启设备管理服务,以释放资源,进行规避
+ */
+ KLOG_INFO() << "restart the service, because IriStart device cannot release resources";
+ QProcess process;
+ process.startDetached(SYSTEMCTL_RESTART_SERVICE);
}
bool MFIriStarDriver::initDriver(const QString &libPath)
--
2.33.0