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

swss: Fixing race condition for rif counters

Open sumanbrcm opened this issue 3 years ago • 1 comments

  • Fixing issue #11621
  • The cleanup code for stale rif counters are now moved to syncd . Earlier as part of fix for issue #2193 the cleanup for stale rif counters was added.
  • But it could create a race condition between orchagent removes RIF rate counters from DB and lua script fetching them.
  • So as a fix all such cleanup has been moved to syncd.

Signed-off-by: Suman Kumar [email protected]

What I did Fix for https://github.com/sonic-net/sonic-buildimage/issues/11621

As a past fix which aimed at removing stale rif counters (https://github.com/sonic-net/sonic-swss/pull/2199) , there is a chance of race condition and it leads to lua script reporting error. To handle this , the rif counters cleanup code(handled in cleanUpRifFromCounterDb) is now called from syncd ( removeCounter ) to avoid such race condition.

Why I did it

The operations in Orchagent and syncd is not synchronous, so while Orchagent deletes the rif counters from Counters Db , the syncd could still access it. In race conditions the lua script trying to fetch rif counters will have errors syslog for such access as it was already deleted by orchagent. The cleanup code is removed from orchagent is added in syncd - it will make sure no such race condition would get hit.

How I verified it

Followed the steps in (https://github.com/sonic-net/sonic-buildimage/issues/11621) :

  1. Create RIF in SONiC, wait till RIF rates are populated in COUNTERS DB
  2. Remove RIF
  3. Repeat the steps multiple times and check if any error syslog is seen (No error syslog is seen)

Also checked cleanup for rif counters.

  1. After RIF creation derived info of oid for RIF from "COUNTERS_RIF_NAME_MAP" 127) "Vlan100" 128) "oid:0x6000000000aa5"

  2. Checked all the tabled in COUNTER_DB which has same OID in keys 127.0.0.1:6379[2]> keys 6000000000aa5 1) "RATES:oid:0x6000000000aa5:RIF" 2) "COUNTERS:oid:0x6000000000aa5" 3) "RATES:oid:0x6000000000aa5" 127.0.0.1:6379[2]>

  3. Deleted the RIF by removing the ip on the intf.

  4. Checked COUNTER_DB again with same OID if there are stale entries or not. No stale entries exist now. 127.0.0.1:6379[2]> keys 6000000000aa5 (empty array) 127.0.0.1:6379[2]>

Details if related

sumanbrcm avatar Oct 13 '22 07:10 sumanbrcm

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: sumanbrcm / name: Suman Kumar (c116d1e9135b7a7f36338a33e5e02a4ab228c393)

@Junchao-Mellanox , @kcudnik
For reviewing. This is related to ( https://github.com/sonic-net/sonic-sairedis/pull/1136 ) This specific pull request is for removal of cleanup code from OA.

sumanbrcm avatar Oct 28 '22 03:10 sumanbrcm

/easycla

sumanbrcm avatar Oct 28 '22 09:10 sumanbrcm

Added @prsunny and @liat-grozovik for merge/related-approval.

sumanbrcm avatar Oct 28 '22 09:10 sumanbrcm

@prsunny @liat-grozovik @kcudnik This is request for merge/related-approval.

sumanbrcm avatar Nov 08 '22 11:11 sumanbrcm

@Junchao-Mellanox @sumanbrcm should we also tagged it for 202205?

liat-grozovik avatar Nov 08 '22 12:11 liat-grozovik

@Junchao-Mellanox @sumanbrcm should we also tagged it for 202205?

yes. I added tag

Junchao-Mellanox avatar Nov 09 '22 00:11 Junchao-Mellanox