Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisPipeline ignore flush when call dtor from another thread. #736

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion common/redispipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "redisreply.h"
#include "rediscommand.h"
#include "dbconnector.h"
#include "logger.h"

#include "unistd.h"
#include "sys/syscall.h"
#define gettid() syscall(SYS_gettid)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no wrapper for gettid() in glibc <= 2.30, so we need use syscall(SYS_gettid)


namespace swss {

Expand All @@ -19,10 +24,20 @@ class RedisPipeline {
, m_remaining(0)
{
m_db = db->newConnector(NEWCONNECTOR_TIMEOUT);
initializeOwnerTid();
}

~RedisPipeline() {
Copy link
Contributor

@qiluo-msft qiluo-msft Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RedisPipeline

Thanks for fixing the bug. It is from the design that DBConnector could be used only in one thread. Do you find similar issues in other classes in swss-common? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I check all dtor in swss-common only find RedisPipeline class run redis command in dtor.

flush();
if (m_ownerTid == gettid())
{
// call flush from different thread will trigger race condition issue.
flush();
}
Copy link
Contributor

@qiluo-msft qiluo-msft Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

Add a notice logging in else branch. The message could be "RedisPipeline dtor is called from another thread, possibly due to exit()" #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

else
{
SWSS_LOG_NOTICE("RedisPipeline dtor is called from another thread, possibly due to exit(), Database: %s", getDbName().c_str());
}

delete m_db;
}

Expand Down Expand Up @@ -125,10 +140,16 @@ class RedisPipeline {
return m_db;
}

void initializeOwnerTid()
{
m_ownerTid = gettid();
}

private:
DBConnector *m_db;
std::queue<int> m_expectedTypes;
size_t m_remaining;
long int m_ownerTid;

void mayflush()
{
Expand Down