Skip to content
Merged
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion common/redispipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "rediscommand.h"
#include "dbconnector.h"

#include "unistd.h"
#include "sys/syscall.h"
#define gettid() syscall(SYS_gettid)
Copy link
Copy Markdown
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 {

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

~RedisPipeline() {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed


delete m_db;
}

Expand Down Expand Up @@ -125,10 +135,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