fix: set change during iteration when dispatching listeners by bdraco · Pull Request #1370 · python-zeroconf/python-zeroconf

@bdraco mentioned this pull request

Apr 12, 2024

20 tasks

@bdraco bdraco changed the title fix: set changed size during iteration when dispatching listeners fix: set size during iteration when dispatching listeners

Apr 12, 2024

@bdraco

An existing listener may add new listeners to process ServiceInfo
when it sees a record. We need to make a copy of the listeners
set before iterating them to avoid `set changed size during iteration`

Fixes
```
2024-04-12 16:31:25.699 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/selector_events.py", line 1248, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "src/zeroconf/_listener.py", line 86, in zeroconf._listener.AsyncListener.datagram_received
  File "src/zeroconf/_listener.py", line 104, in zeroconf._listener.AsyncListener.datagram_received
  File "src/zeroconf/_listener.py", line 175, in zeroconf._listener.AsyncListener._process_datagram_at_time
  File "src/zeroconf/_handlers/record_manager.py", line 161, in zeroconf._handlers.record_manager.RecordManager.async_updates_from_response
  File "src/zeroconf/_handlers/record_manager.py", line 70, in zeroconf._handlers.record_manager.RecordManager.async_updates_complete
RuntimeError: set changed size during iteration
```

@bdraco bdraco changed the title fix: set size during iteration when dispatching listeners fix: set change during iteration when dispatching listeners

Apr 12, 2024

@bdraco bdraco marked this pull request as ready for review

April 12, 2024 21:47

@bdraco bdraco deleted the set_changed_during_iteration branch

April 12, 2024 21:47