-
Notifications
You must be signed in to change notification settings - Fork 283
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
namespace swss { | ||
|
||
|
@@ -19,10 +24,20 @@ class RedisPipeline { | |
, m_remaining(0) | ||
{ | ||
m_db = db->newConnector(NEWCONNECTOR_TIMEOUT); | ||
initializeOwnerTid(); | ||
} | ||
|
||
~RedisPipeline() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
@@ -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() | ||
{ | ||
|
There was a problem hiding this comment.
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)