sonic-swss-common
sonic-swss-common copied to clipboard
Add thread safe guard to throw exception when share DBConnection cross threads
Why I did it
For performance erason, swsscommon is not thread safe. Code using swsscommon may make mistake to share db connection cross thread, and it's difficult to debug. To slove this issue, add ThreadSafeGuard class to detect and throw exception when db connection shared by multiple thread.
How I did it
Add ThreadSafeCheck class to check and throw exception when DBConnect shared by multiple thread.
How to verify it
Pass all test case. Add new test case to cover new code.
Which release branch to backport (provide reason below if selected)
- [ ] 201811
- [ ] 201911
- [ ] 202006
- [ ] 202012
- [ ] 202106
- [ ] 202111
Description for the changelog
Add ThreadSafeCheck class to check and throw exception when DBConnect shared by multiple thread.
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
@liuh-80 Can this PR fix the issue https://github.com/sonic-net/sonic-buildimage/issues/10883? If multiple threads run different commands for same DBConnection at same time in caclmgrd, will this change avoid crash and just return exception?