diff mbox series

[ovs-dev] ovs-dpctl-top: Fix RuntimeError with resizing flow dict during iteration.

Message ID 20240830152126.684992-1-aconole@redhat.com
State Accepted
Delegated to: aaron conole
Headers show
Series [ovs-dev] ovs-dpctl-top: Fix RuntimeError with resizing flow dict during iteration. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Aaron Conole Aug. 30, 2024, 3:21 p.m. UTC
Python does not allow modifying a dictionary or list while iterating
over the elements.  The common idom to work around this is to create
a copy of the keys or elements and then use that information to delete
the corresponding entries from the original dictionary.

This patch changes the iteration to use an intermediate copy and then
modify the original dictionary.  This avoids the associated
RuntimeError.

Reported-by: Eelco Chaudron <echaudro@redhat.com>
Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2024-August/417000.html
Fixes: 14b4c575c284 ("utilities: a top like tool for ovs-dpctl dump-flows.")
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 utilities/ovs-dpctl-top.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eelco Chaudron Sept. 2, 2024, 9:17 a.m. UTC | #1
On 30 Aug 2024, at 17:21, Aaron Conole wrote:

> Python does not allow modifying a dictionary or list while iterating
> over the elements.  The common idom to work around this is to create
> a copy of the keys or elements and then use that information to delete
> the corresponding entries from the original dictionary.
>
> This patch changes the iteration to use an intermediate copy and then
> modify the original dictionary.  This avoids the associated
> RuntimeError.
>
> Reported-by: Eelco Chaudron <echaudro@redhat.com>
> Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2024-August/417000.html
> Fixes: 14b4c575c284 ("utilities: a top like tool for ovs-dpctl dump-flows.")
> Signed-off-by: Aaron Conole <aconole@redhat.com>

Thanks Aaron for fixing this.

Acked-by: Eelco Chaudron <echaudro@redhat.com>
Aaron Conole Sept. 3, 2024, 12:05 p.m. UTC | #2
Eelco Chaudron <echaudro@redhat.com> writes:

> On 30 Aug 2024, at 17:21, Aaron Conole wrote:
>
>> Python does not allow modifying a dictionary or list while iterating
>> over the elements.  The common idom to work around this is to create
>> a copy of the keys or elements and then use that information to delete
>> the corresponding entries from the original dictionary.
>>
>> This patch changes the iteration to use an intermediate copy and then
>> modify the original dictionary.  This avoids the associated
>> RuntimeError.
>>
>> Reported-by: Eelco Chaudron <echaudro@redhat.com>
>> Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2024-August/417000.html
>> Fixes: 14b4c575c284 ("utilities: a top like tool for ovs-dpctl dump-flows.")
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>
> Thanks Aaron for fixing this.
>
> Acked-by: Eelco Chaudron <echaudro@redhat.com>

Applied.  Thanks.
diff mbox series

Patch

diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index 1708c2f374..f2d5bae6a6 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -1007,7 +1007,7 @@  class FlowDB:
     def decay(self, decayTimeInSeconds):
         """ Decay content. """
         now = datetime.datetime.now()
-        for (key, value) in self._flows.items():
+        for (key, value) in list(self._flows.items()):
             (stats_dict, updateTime) = value
             delta = now - updateTime