Skip to content

Commit b6a59ba

Browse files
XIONE-15050: WPEFramework crash with function __libc_do_syscall. (rdkcentral#5654) (rdkcentral#5958)
* XIONE-15050: WPEFramework crash with function __libc_do_syscall. (rdkcentral#5654) * detachable function change (cherry picked from commit f02332a)
1 parent 309dcb1 commit b6a59ba

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

Network/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ All notable changes to this RDK Service will be documented in this file.
1616

1717
* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.
1818

19+
20+
## [1.3.13] - 2025-01-07
21+
### Fixed
22+
- Fix crash in the WPEFramework connectivity monitor destructor
23+
1924
## [1.3.12] - 2025-01-02
2025
### Security
2126
- Resolved security vulnerabilities

Network/Network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using namespace std;
3535

3636
#define API_VERSION_NUMBER_MAJOR 1
3737
#define API_VERSION_NUMBER_MINOR 3
38-
#define API_VERSION_NUMBER_PATCH 12
38+
#define API_VERSION_NUMBER_PATCH 13
3939

4040
/* Netsrvmgr Based Macros & Structures */
4141
#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR"

Network/NetworkConnectivity.cpp

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace WPEFramework {
2222
namespace Plugin {
2323

24+
static int threadCount = 0;
2425
bool EndpointCache::isEndpointCashFileExist()
2526
{
2627
std::ifstream fileStream(CachefilePath);
@@ -457,25 +458,18 @@ namespace WPEFramework {
457458

458459
timeout.store(timeoutInSeconds >= MONITOR_TIMEOUT_INTERVAL_MIN ? timeoutInSeconds:defaultTimeoutInSec);
459460

460-
if (isMonitorThreadRunning() && stopFlag == false)
461+
if (isMonitorThreadRunning())
461462
{
462463
isContinuesMonitoringNeeded = true;
463464
resetTimeout = true;
464465
cv_.notify_all();
465466
}
466467
else
467468
{
468-
if (thread_.joinable())
469-
{
470-
LOGWARN("Connectivity Monitor joinable Thread is active");
471-
stopFlag = true;
472-
cv_.notify_all();
473-
thread_.join();
474-
}
475-
476469
isContinuesMonitoringNeeded = true;
477470
stopFlag = false;
478471
thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this);
472+
thread_.detach();
479473
LOGINFO("Connectivity monitor started with %d", timeout.load());
480474
}
481475

@@ -490,34 +484,27 @@ namespace WPEFramework {
490484
return false;
491485
}
492486

493-
if (isMonitorThreadRunning() && stopFlag == false)
487+
if (isMonitorThreadRunning())
494488
{
495-
LOGINFO("Connectivity Monitor Thread is active so notify");
489+
LOGINFO("Connectivity monitor thread is active so notify");
496490
g_internetState = nsm_internetState::UNKNOWN;
497491
cv_.notify_all();
498492
}
499493
else
500494
{
501-
if (thread_.joinable())
502-
{
503-
LOGWARN("Connectivity Monitor joinable Thread is active");
504-
stopFlag = true;
505-
cv_.notify_all();
506-
thread_.join();
507-
}
508-
509495
stopFlag = false;
510496
timeout.store(timeoutInSeconds >= MONITOR_TIMEOUT_INTERVAL_MIN ? timeoutInSeconds:defaultTimeoutInSec);
511497
thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this);
512-
LOGINFO("Initial Connectivity Monitoring started with %d", timeout.load());
498+
thread_.detach();
499+
LOGINFO("Initial connectivity monitoring started with %d", timeout.load());
513500
}
514501

515502
return true;
516503
}
517504

518505
bool ConnectivityMonitor::isMonitorThreadRunning()
519506
{
520-
return thread_.joinable();
507+
return isRunning.load();
521508
}
522509

523510
bool ConnectivityMonitor::stopInitialConnectivityMonitoring()
@@ -528,42 +515,55 @@ namespace WPEFramework {
528515
return true;
529516
}
530517

531-
stopFlag = true;
532-
cv_.notify_all();
533-
534-
if (thread_.joinable())
535-
thread_.join();
518+
int tryCount = 5; // max 4 sec
519+
do {
520+
stopFlag = true;
521+
cv_.notify_all();
522+
sleep(1);
523+
} while(isMonitorThreadRunning() && (--tryCount > 0));
536524

537-
LOGINFO("Initial Connectivity Monitor stopped");
525+
if(isMonitorThreadRunning() && isContinuesMonitoringNeeded == false)
526+
{
527+
LOGERR("Initial connectivity monitor not stopped");
528+
return false;
529+
}
530+
else
531+
LOGINFO("Initial connectivity monitor stopped");
538532

539533
return true;
540534
}
541535

542536
bool ConnectivityMonitor::stopContinuousConnectivityMonitoring()
543537
{
544-
stopFlag = true;
545-
cv_.notify_all();
538+
int tryCount = 5; // max 5 sec
539+
do {
540+
stopFlag = true;
541+
cv_.notify_all();
542+
sleep(1);
543+
} while(isMonitorThreadRunning() && (--tryCount > 0));
546544

547-
if (thread_.joinable())
548-
thread_.join();
545+
if(isMonitorThreadRunning())
546+
{
547+
LOGERR("Continuous connectivity monitor not stopped");
548+
return false;
549+
}
550+
else
551+
LOGINFO("Continuous connectivity monitor stopped");
549552

550-
isContinuesMonitoringNeeded = false;
551-
LOGINFO("Continuous Connectivity monitor stopped");
552553
return true;
553554
}
554555

555556
void ConnectivityMonitor::signalConnectivityMonitor()
556557
{
557-
if (isMonitorThreadRunning())
558-
{
559-
/* Reset the global value to UNKNOWN state so the cache is reset */
560-
g_internetState = nsm_internetState::UNKNOWN;
561-
cv_.notify_all();
562-
}
558+
/* Reset the global value to UNKNOWN state so the cache is reset */
559+
g_internetState = nsm_internetState::UNKNOWN;
560+
cv_.notify_all();
563561
}
564562

565563
void ConnectivityMonitor::connectivityMonitorFunction()
566564
{
565+
isRunning = true;
566+
threadCount++;
567567
nsm_internetState InternetConnectionState = nsm_internetState::UNKNOWN;
568568
int notifyWaitCount = DEFAULT_MONITOR_RETRY_COUNT;
569569
int tempTimeout = defaultTimeoutInSec;
@@ -641,9 +641,18 @@ namespace WPEFramework {
641641
}
642642

643643
} while (!stopFlag);
644-
645644
g_internetState = nsm_internetState::UNKNOWN;
646645
LOGWARN("Connectivity monitor exiting");
646+
threadCount--;
647+
isRunning = false;
648+
}
649+
650+
ConnectivityMonitor::~ConnectivityMonitor() {
651+
LOGINFO("~ConnectivityMonitor");
652+
stopContinuousConnectivityMonitoring();
653+
sleep(1);
654+
if(threadCount > 0)
655+
LOGWARN("thread still active %d", threadCount);
647656
}
648657

649658
} // namespace Plugin

Network/NetworkConnectivity.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,12 @@ namespace WPEFramework {
114114
bool isMonitorThreadRunning();
115115
void signalConnectivityMonitor();
116116

117-
ConnectivityMonitor() : stopFlag(false), resetTimeout(false), isContinuesMonitoringNeeded(false)
117+
ConnectivityMonitor() : isRunning(false), stopFlag(false), resetTimeout(false), isContinuesMonitoringNeeded(false)
118118
{
119119
setConnectivityMonitorEndpoints(getConnectivityDefaultEndpoints());
120120
}
121121

122-
~ConnectivityMonitor() {
123-
LOGINFO("~ConnectivityMonitor");
124-
stopContinuousConnectivityMonitoring();
125-
}
122+
~ConnectivityMonitor();
126123
private:
127124

128125
std::vector<std::string> getConnectivityMonitorEndpoints();
@@ -133,6 +130,7 @@ namespace WPEFramework {
133130
EndpointCache& endpointCache = EndpointCache::getInstance();
134131

135132
std::thread thread_;
133+
std::atomic<bool> isRunning;
136134
std::atomic<bool> stopFlag;
137135
std::atomic<bool> resetTimeout;
138136
std::atomic<bool> isContinuesMonitoringNeeded;

0 commit comments

Comments
 (0)