Skip to content

Commit

Permalink
XIONE-15050: WPEFramework crash with function __libc_do_syscall. (rdk…
Browse files Browse the repository at this point in the history
…central#5654)

* detachable function change

* Update CHANGELOG.md

* Update Network.cpp
  • Loading branch information
cmuhammedrafi authored Aug 29, 2024
1 parent ade21ca commit f02332a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 46 deletions.
4 changes: 4 additions & 0 deletions Network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ All notable changes to this RDK Service will be documented in this file.

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

## [1.3.12] - 2024-06-19
### Fixed
- Fix crash in the WPEFramework connectivity monitor destructor

## [1.3.11] - 2024-06-19
### Fixed
- onInternetStatus event not posting error fix
Expand Down
2 changes: 1 addition & 1 deletion Network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace std;

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 3
#define API_VERSION_NUMBER_PATCH 11
#define API_VERSION_NUMBER_PATCH 12

/* Netsrvmgr Based Macros & Structures */
#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR"
Expand Down
89 changes: 49 additions & 40 deletions Network/NetworkConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace WPEFramework {
namespace Plugin {

static int threadCount = 0;
bool EndpointCache::isEndpointCashFileExist()
{
std::ifstream fileStream(CachefilePath);
Expand Down Expand Up @@ -457,25 +458,18 @@ namespace WPEFramework {

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

if (isMonitorThreadRunning() && stopFlag == false)
if (isMonitorThreadRunning())
{
isContinuesMonitoringNeeded = true;
resetTimeout = true;
cv_.notify_all();
}
else
{
if (thread_.joinable())
{
LOGWARN("Connectivity Monitor joinable Thread is active");
stopFlag = true;
cv_.notify_all();
thread_.join();
}

isContinuesMonitoringNeeded = true;
stopFlag = false;
thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this);
thread_.detach();
LOGINFO("Connectivity monitor started with %d", timeout.load());
}

Expand All @@ -490,34 +484,27 @@ namespace WPEFramework {
return false;
}

if (isMonitorThreadRunning() && stopFlag == false)
if (isMonitorThreadRunning())
{
LOGINFO("Connectivity Monitor Thread is active so notify");
LOGINFO("Connectivity monitor thread is active so notify");
g_internetState = nsm_internetState::UNKNOWN;
cv_.notify_all();
}
else
{
if (thread_.joinable())
{
LOGWARN("Connectivity Monitor joinable Thread is active");
stopFlag = true;
cv_.notify_all();
thread_.join();
}

stopFlag = false;
timeout.store(timeoutInSeconds >= MONITOR_TIMEOUT_INTERVAL_MIN ? timeoutInSeconds:defaultTimeoutInSec);
thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this);
LOGINFO("Initial Connectivity Monitoring started with %d", timeout.load());
thread_.detach();
LOGINFO("Initial connectivity monitoring started with %d", timeout.load());
}

return true;
}

bool ConnectivityMonitor::isMonitorThreadRunning()
{
return thread_.joinable();
return isRunning.load();
}

bool ConnectivityMonitor::stopInitialConnectivityMonitoring()
Expand All @@ -528,42 +515,55 @@ namespace WPEFramework {
return true;
}

stopFlag = true;
cv_.notify_all();

if (thread_.joinable())
thread_.join();
int tryCount = 5; // max 4 sec
do {
stopFlag = true;
cv_.notify_all();
sleep(1);
} while(isMonitorThreadRunning() && (--tryCount > 0));

LOGINFO("Initial Connectivity Monitor stopped");
if(isMonitorThreadRunning() && isContinuesMonitoringNeeded == false)
{
LOGERR("Initial connectivity monitor not stopped");
return false;
}
else
LOGINFO("Initial connectivity monitor stopped");

return true;
}

bool ConnectivityMonitor::stopContinuousConnectivityMonitoring()
{
stopFlag = true;
cv_.notify_all();
int tryCount = 5; // max 5 sec
do {
stopFlag = true;
cv_.notify_all();
sleep(1);
} while(isMonitorThreadRunning() && (--tryCount > 0));

if (thread_.joinable())
thread_.join();
if(isMonitorThreadRunning())
{
LOGERR("Continuous connectivity monitor not stopped");
return false;
}
else
LOGINFO("Continuous connectivity monitor stopped");

isContinuesMonitoringNeeded = false;
LOGINFO("Continuous Connectivity monitor stopped");
return true;
}

void ConnectivityMonitor::signalConnectivityMonitor()
{
if (isMonitorThreadRunning())
{
/* Reset the global value to UNKNOWN state so the cache is reset */
g_internetState = nsm_internetState::UNKNOWN;
cv_.notify_all();
}
/* Reset the global value to UNKNOWN state so the cache is reset */
g_internetState = nsm_internetState::UNKNOWN;
cv_.notify_all();
}

void ConnectivityMonitor::connectivityMonitorFunction()
{
isRunning = true;
threadCount++;
nsm_internetState InternetConnectionState = nsm_internetState::UNKNOWN;
int notifyWaitCount = DEFAULT_MONITOR_RETRY_COUNT;
int tempTimeout = defaultTimeoutInSec;
Expand Down Expand Up @@ -635,9 +635,18 @@ namespace WPEFramework {
}

} while (!stopFlag);

g_internetState = nsm_internetState::UNKNOWN;
LOGWARN("Connectivity monitor exiting");
threadCount--;
isRunning = false;
}

ConnectivityMonitor::~ConnectivityMonitor() {
LOGINFO("~ConnectivityMonitor");
stopContinuousConnectivityMonitoring();
sleep(1);
if(threadCount > 0)
LOGWARN("thread still active %d", threadCount);
}

} // namespace Plugin
Expand Down
8 changes: 3 additions & 5 deletions Network/NetworkConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ namespace WPEFramework {
bool isMonitorThreadRunning();
void signalConnectivityMonitor();

ConnectivityMonitor() : stopFlag(false), resetTimeout(false), isContinuesMonitoringNeeded(false)
ConnectivityMonitor() : isRunning(false), stopFlag(false), resetTimeout(false), isContinuesMonitoringNeeded(false)
{
setConnectivityMonitorEndpoints(getConnectivityDefaultEndpoints());
}

~ConnectivityMonitor() {
LOGINFO("~ConnectivityMonitor");
stopContinuousConnectivityMonitoring();
}
~ConnectivityMonitor();
private:

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

std::thread thread_;
std::atomic<bool> isRunning;
std::atomic<bool> stopFlag;
std::atomic<bool> resetTimeout;
std::atomic<bool> isContinuesMonitoringNeeded;
Expand Down

0 comments on commit f02332a

Please sign in to comment.