@@ -93,20 +93,14 @@ def __init__(self, configuration: Configuration, **kwargs: Unpack[EventManagerOp
9393 """Future that resolves when the connection to the platform websocket is established."""
9494
9595 self ._context_depth = 0
96- """Nesting depth of active `async with` contexts, tracked independently of the parent's ref counting.
97-
98- The platform websocket machinery is started on the outermost enter (0 -> 1) and torn down on the
99- outermost exit (1 -> 0); nested enters/exits reuse the single existing connection.
100- """
96+ """Nesting depth of active contexts; the outermost enter/exit (0 <-> 1) starts/tears down the websocket."""
10197
10298 @override
10399 async def __aenter__ (self ) -> Self :
104100 await super ().__aenter__ ()
105101
106- # Ref-count nested contexts (e.g. a crawler entering the same event manager) with our own counter,
107- # incremented right after a successful parent enter, rather than reading the parent's private ref-count
108- # internals (whose mutation timing we would otherwise depend on). Only the outermost enter (0 -> 1) starts
109- # the platform websocket machinery; a nested enter reuses the connection instead of opening a second one.
102+ # Track nesting depth ourselves rather than reading the parent's private ref count. Only the outermost
103+ # enter (0 -> 1) starts the websocket machinery; a nested enter reuses the existing connection.
110104 self ._context_depth += 1
111105 if self ._context_depth > 1 :
112106 return self
@@ -135,9 +129,8 @@ async def __aexit__(
135129 exc_value : BaseException | None ,
136130 exc_traceback : TracebackType | None ,
137131 ) -> None :
138- # Mirror the enter's own ref counting: only the outermost exit (1 -> 0) tears down the platform websocket
139- # machinery. A nested exit must leave the connection and its processing task intact for the still-active
140- # outer context.
132+ # Only the outermost exit (1 -> 0) tears down the websocket machinery; a nested exit must leave the
133+ # connection and its processing task intact for the still-active outer context.
141134 if self ._context_depth == 1 :
142135 # Cancel the task before closing the websocket so that the closed connection is not treated as a drop
143136 # and followed by a reconnect attempt.
0 commit comments