Skip to content

Commit 57f1af6

Browse files
authored
Fix: not to use blocking get_all() after keys() (#255)
In a dynamic environment, it is possible that some of the keys may disappear between invoking keys() and get_all(). Prevent unnecessary timeout of blocking get_all().
1 parent 33fdf9d commit 57f1af6

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/sonic_ax_impl/mibs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,15 @@ def dbs_get_all(dbs, db_name, _hash, *args, **kwargs):
630630
result = {}
631631
# If there are multiple namespaces, _hash might not be
632632
# present in all namespace, ignore if not present in a
633-
# specfic namespace.
633+
# specific namespace.
634634
if len(dbs) > 1:
635635
tmp_kwargs = kwargs.copy()
636636
tmp_kwargs['blocking'] = False
637637
else:
638638
tmp_kwargs = kwargs
639639
for db_conn in dbs:
640640
ns_result = db_conn.get_all(db_name, _hash, *args, **tmp_kwargs)
641-
if ns_result is not None:
641+
if ns_result:
642642
result.update(ns_result)
643643
return result
644644

src/sonic_ax_impl/mibs/ietf/rfc1213.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ def update_data(self):
151151
ipnstr = routestr[len("ROUTE_TABLE:"):]
152152
if ipnstr == "0.0.0.0/0":
153153
ipn = ipaddress.ip_network(ipnstr)
154-
ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=True)
155-
nexthops = ent["nexthop"]
156-
for nh in nexthops.split(','):
157-
# TODO: if ipn contains IP range, create more sub_id here
158-
sub_id = ip2byte_tuple(ipn.network_address)
159-
self.route_list.append(sub_id)
160-
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
161-
break # Just need the first nexthop
154+
ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=False)
155+
if ent:
156+
nexthops = ent["nexthop"]
157+
for nh in nexthops.split(','):
158+
# TODO: if ipn contains IP range, create more sub_id here
159+
sub_id = ip2byte_tuple(ipn.network_address)
160+
self.route_list.append(sub_id)
161+
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
162+
break # Just need the first nexthop
162163

163164
self.route_list.sort()
164165

src/sonic_ax_impl/mibs/ietf/rfc4363.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def update_data(self):
7979
mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e))
8080
continue
8181

82-
ent = Namespace.dbs_get_all(self.db_conn, mibs.ASIC_DB, s, blocking=True)
82+
ent = Namespace.dbs_get_all(self.db_conn, mibs.ASIC_DB, s, blocking=False)
8383
# Example output: oid:0x3a000000000608
8484
bridge_port_id = ent["SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:]
8585
if bridge_port_id not in self.if_bpid_map:

0 commit comments

Comments
 (0)