You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jd...@apache.org on 2023/09/29 11:18:23 UTC

[qpid-python] 05/09: QPID-8631: fix RuntimeError: dictionary changed size during iteration

This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-python.git

commit 1ff4397672f4c52f12530bd9470de0a67aa7378e
Author: Jiri Daněk <jd...@redhat.com>
AuthorDate: Tue Apr 11 11:03:11 2023 +0200

    QPID-8631: fix RuntimeError: dictionary changed size during iteration
    
    ```
      Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/threading.py", line 932, in _bootstrap_inner
          self.run()
        File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/threading.py", line 870, in run
          self._target(*self._args, **self._kwargs)
        File "/home/runner/work/qpid-python/qpid-python/qpid/connection.py", line 190, in run
          self.detach_all()
        File "/home/runner/work/qpid-python/qpid-python/qpid/connection.py", line 140, in detach_all
          self.run()
        File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/threading.py", line 870, in run
          for ssn in self.attached.values():
    ```
    
    This is Python's version of the concurrent modification exception in Java.
---
 qpid/client.py              | 2 +-
 qpid/connection.py          | 2 +-
 qpid/messaging/endpoints.py | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/qpid/client.py b/qpid/client.py
index 305f6b3..f31edd8 100644
--- a/qpid/client.py
+++ b/qpid/client.py
@@ -248,7 +248,7 @@ class ClientDelegate(Delegate):
     self.client.reason = reason
     self.client.started.set()
     with self.client.lock:
-      for queue in self.client.queues.values():
+      for queue in list(self.client.queues.values()):
         queue.close(reason)
 
 class StructFactory:
diff --git a/qpid/connection.py b/qpid/connection.py
index 0905aaa..7d1785f 100644
--- a/qpid/connection.py
+++ b/qpid/connection.py
@@ -137,7 +137,7 @@ class Connection(Framer):
     self.lock.acquire()
     self.failed = True
     try:
-      for ssn in self.attached.values():
+      for ssn in list(self.attached.values()):
         if self.close_code[0] != 200:
           ssn.exceptions.append(self.close_code)
         self.detach(ssn.name, ssn.channel)
diff --git a/qpid/messaging/endpoints.py b/qpid/messaging/endpoints.py
index 56c2426..95db77e 100644
--- a/qpid/messaging/endpoints.py
+++ b/qpid/messaging/endpoints.py
@@ -382,7 +382,7 @@ class Connection(Endpoint):
     Close the connection and all sessions.
     """
     try:
-      for ssn in self.sessions.values():
+      for ssn in list(self.sessions.values()):
         ssn.close(timeout=timeout)
     finally:
       self.detach(timeout=timeout)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org