Skip to content

refactor: split task group into data-plane and control-plane - #950

Open
bennyz wants to merge 1 commit into
bz/restart-2from
bz/restart-3
Open

refactor: split task group into data-plane and control-plane#950
bennyz wants to merge 1 commit into
bz/restart-2from
bz/restart-3

Conversation

@bennyz

@bennyz bennyz commented Aug 3, 2026

Copy link
Copy Markdown
Member

Introduce an outer conns_tg (data-plane) that hosts handle_lease
and _handle_client_conn, and an inner tg (control-plane) that hosts
Status/Listen streams and _handle_end_session.

When _cancel_with_fatal_error fires (Status stream terminal error),
only the inner group is cancelled. Active client tunnels on conns_tg
remain alive until serve() explicitly cancels the outer group.

Add TestTaskGroupIsolation to verify a connection task survives
control-plane cancellation.

Depends on #949
Next: #951

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 818175a0-439e-442d-af05-041907562a54

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

self._request_lease_release,
)
tg.start_soon(self.handle_lease, status.lease_name, tg, lease_scope)
conns_tg.start_soon(self.handle_lease, status.lease_name, conns_tg, lease_scope)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if session_for_lease() raises during handle_lease, execution jumps to the outer finally without entering the inner try/finally that cleans up. The exporter hence could hang permanently.

Comment on lines +1167 to +1176
async with create_task_group() as conns_tg:
await self._run_control_plane(status_tx, status_rx, conns_tg)
if self._fatal_stream_error:
name, err = self._fatal_stream_error
logger.warning(
"Control plane down (%s: %s), cancelling active connections",
name,
err,
)
conns_tg.cancel_scope.cancel()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try keeping connections alive during control-plane recovery?

if previous_state == LeaseState.IDLE and status.lease_name != "":
self._on_lease_acquired(status, tg)
self._on_lease_acquired(status, tg, conns_tg)
elif (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider clearing _lease_context in _on_lease_released after the shielded wait completes, and have the handle_lease finally guard against double-clearing.

# Start task to handle EndSession requests (runs afterLease hook when client signals done)
tg.start_soon(self._handle_end_session, lease_scope)
# Runs on control-plane group so it's cancelled with Status/Listen, not data-plane
self._tg.start_soon(self._handle_end_session, lease_scope)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also moving the Listen stream to self._tg so its lifecycle matches the other control-plane streams.

@bennyz
bennyz force-pushed the bz/restart-3 branch 2 times, most recently from 479b280 to 4f46d3e Compare August 3, 2026 15:33
@bennyz
bennyz force-pushed the bz/restart-3 branch 3 times, most recently from a61b1ec to 2cccab8 Compare August 3, 2026 17:43
@bennyz
bennyz force-pushed the bz/restart-3 branch 3 times, most recently from 4ddbb3d to f0b2ec4 Compare August 4, 2026 07:03
Introduce an outer conns_tg (data-plane) that hosts handle_lease
and _handle_client_conn, and an inner tg (control-plane) that hosts
Status/Listen streams and _handle_end_session.

When _cancel_with_fatal_error fires (Status stream terminal error),
only the inner group is cancelled. Active client tunnels on conns_tg
remain alive until serve() explicitly cancels the outer group.

Add TestTaskGroupIsolation to verify a connection task survives
control-plane cancellation.

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Assisted-by: claude-opus-4.6

@bkhizgiy bkhizgiy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good from my side.

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.

3 participants