sonic-swss-common icon indicating copy to clipboard operation
sonic-swss-common copied to clipboard

Add thread safe guard to throw exception when share DBConnection cross threads

Open liuh-80 opened this issue 2 years ago • 5 comments

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)

liuh-80 avatar Jun 20 '22 07:06 liuh-80

/azp run

liuh-80 avatar Jun 23 '22 00:06 liuh-80

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 23 '22 00:06 azure-pipelines[bot]

/azp run

liuh-80 avatar Jul 14 '22 08:07 liuh-80

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jul 14 '22 08:07 azure-pipelines[bot]

@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?

ZhaohuiS avatar Sep 12 '22 11:09 ZhaohuiS