Possible race in send_packet: AttributeError on _ezsp.set_extended_timeout when disconnect() runs concurrently
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start in bellows/zigbee/application.py, reading send_packet() around the controller-running check and _ezsp.set_extended_timeout() call, then compare it with disconnect() and its _req_lock usage. First confirm whether in-flight sends can reach that call after disconnect clears _ezsp; the issue reports no captured interleaving or synthetic reproducer. Done means the race is confirmed or ruled out and, if confirmed, the chosen fix handles disconnect during a send without leaving the failure path unclear.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
⚠️ This is an investigation, not a confirmed reproduction. I read the code and identified a window that seems reachable, but I do not have a debug log proving the exact interleaving. Filing in case it helps maintainers triage a recent user report.
A user report in home-assistant/core (home-assistant/core#172247, Home Assistant 2026.5.4 with bellows 0.49.1 / zigpy 1.4.1 / Python 3.14.2, ZBT-1 over USB) includes this traceback from zigpy.zcl:
AttributeError: 'NoneType' object has no attribute 'set_extended_timeout'
File ".../bellows/zigbee/application.py", line 1030, in send_packet
await self._ezsp.set_extended_timeout(...)
This signature does not match the symptom of home-assistant/core#130548 (which raises ControllerError("ApplicationController is not running") from the explicit guard) and I cannot find any other report of set_extended_timeout failing on None. It looks like a separate, undocumented bug.
The window
In bellows/zigbee/application.py (master at 0.49.1):
async def send_packet(self, packet):
if not self.is_controller_running: # L957: check passes
raise ControllerError("ApplicationController is not running")
...
async with self._limit_concurrency(priority=...): # awaits semaphore
...
async with self._req_lock: # awaits lock
if packet.dst.addr_mode == zigpy.types.AddrMode.NWK:
if device is not None:
await self._ezsp.set_extended_timeout( # L1030
...
)
disconnect() (line 611-615):
async def disconnect(self):
self.controller_event.clear() # L612
if self._ezsp is not None:
await self._ezsp.disconnect() # L614 — awaits
self._ezsp = None # L615
disconnect() does not acquire _req_lock. So between send_packet's guard at L957 and its use of self._ezsp at L1030 there are two await boundaries (_limit_concurrency, _req_lock). If disconnect() runs in the gap, it clears controller_event, awaits the EZSP disconnect, and sets _ezsp = None. When send_packet resumes inside _req_lock, the dereference at L1030 raises AttributeError.
Note that is_controller_running (L113-114) is controller_event.is_set() and self._ezsp.is_ezsp_running, so if _ezsp were already None at check time the guard would itself NPE — meaning the race window is strictly after the guard, not at the guard.
Why this can fire in practice (hypothesis)
A few concurrent paths reach disconnect():
- Watchdog failure →
_watchdog_loop(zigpy/application.py:886-902) callsconnection_lost(exc)→ ZHA emitsConnectionLostEvent→ HA core helperhandle_connection_lostcallshass.config_entries.async_schedule_reload(...)→ unload →shutdown()→disconnect(). - ZHA setup failure:
zha.application.gateway.async_initializecatches and doesawait self.shutdown()on any exception during_async_initialize. - Home Assistant's bootstrap stage-2 cancel (300 s,
homeassistant/bootstrap.py:141) cancelling a slow ZHA setup, which propagates into the same shutdown path.
In all three, ZCL requests already issued by device interviews or by user actions can still be in send_packet past the guard and not yet at L1030. The #172247 reporter sees the crash during setup and also reports HA's "Bootstrap stage 2 timeout", consistent with path 3.
What I have not verified
- No debug log captured showing the interleaving in flight. The reporter only included excerpts.
- I have not attempted a synthetic reproducer.
- I have not checked whether HA core or ZHA somehow ensures all in-flight
send_packettasks are awaited beforedisconnect()is reached —zigpy.application.shutdown()does cancelself._tasks, but user-initiated request coroutines are not registered there.
Possible directions for a fix
Sketching without picking one:
- Re-check
is_controller_running(orself._ezsp is not None) inside_req_lockinsend_packet, raisingControllerErrorcleanly instead of NPE-ing. - Acquire
_req_lockinsidedisconnect()so it serialises with in-flight sends. Tradeoff:_ezsp.disconnect()may be slow, so holding_req_lockcould delay legitimate cleanup, and a misbehaving radio could deadlock the lock acquisition. - Wrap the L1030 dereference in a small helper that handles the
_ezsp is Nonecase explicitly.
Happy to provide whatever extra context or logs would help, and I can ask the original reporter for a full debug log if useful.
- Ngôn ngữ chính
- Python
- Star
- 221
- Fork
- 104
- Merge trung bình
- 5 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của zigpy/bellows
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
-
Stale NCP source route is never invalidated after SOURCE_ROUTE_FAILURE; end device unreachable until re-pairCó thể đã có người làm @puddly đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của zigpy/bellows
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
NL-BioImaging/biomero#136 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Grayscale PNGs with partial transparency can turn gray pixels whiteCó thể đã có người làm @ktz03 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Add deterministic regex redaction for IDs, IBANs, and account numbers in summaries & keywordsĐang mởenhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
floorianmb/tidywise#5 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-score/tools#82 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày