Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set change during iteration when dispatching listeners #1370

Merged
merged 1 commit into from Apr 12, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Apr 12, 2024

An existing listener may add new listeners to process ServiceInfo when it sees a record (or for other reasons). 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 changed size during iteration when dispatching listeners fix: set size during iteration when dispatching listeners Apr 12, 2024
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 force-pushed the set_changed_during_iteration branch from cc9f207 to d5de7a5 Compare April 12, 2024 21:44
@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 merged commit e9f8aa5 into master Apr 12, 2024
24 of 26 checks passed
@bdraco bdraco deleted the set_changed_during_iteration branch April 12, 2024 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant