Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

unregister from controller only on proper exit#659

Merged
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
michalskrivanek:keep-registered
Sep 29, 2025
Merged

unregister from controller only on proper exit#659
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
michalskrivanek:keep-registered

Conversation

@michalskrivanek
Copy link
Copy Markdown
Contributor

@michalskrivanek michalskrivanek commented Sep 26, 2025

exceptions raised duing serve() and lease changes keep the exporter registered with controller to avoid quick online/offline transitions since the internal logic restarts the jumpstarter child process within few seconds. On termination signal the unregistration still happens as the parent process also terminates. Note it still causes offline/online bounce if it is immediatelly restarted via systemd service for example.

Summary by CodeRabbit

  • Bug Fixes
    • Improved shutdown handling on OS signals (e.g., SIGHUP) so the CLI and exporter terminate cleanly.
    • Ensures deregistration during signal-triggered stops to prevent stale registrations or lingering sessions.
    • Made cleanup for immediate and normal shutdowns more consistent, reducing hangs and unexpected behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 26, 2025

Walkthrough

Exporter.stop gained a new parameter to record an intent to unregister; CLI signal handlers now call stop(..., should_unregister=True). Unregistration during cleanup is performed only when the exporter was registered and the new internal _unregister flag is set.

Changes

Cohort / File(s) Summary
Exporter stop/unregister gating
packages/jumpstarter/jumpstarter/exporter/exporter.py
Added should_unregister param to Exporter.stop(wait_for_lease_exit=False, should_unregister=False). Stores intent in internal _unregister, sets _unregister on immediate stop, and only calls controller unregister() during cleanup if registered and _unregister are true. Updated logging and lease-exit stop path to pass should_unregister=True.
CLI signal handling stop invocation
packages/jumpstarter-cli/jumpstarter_cli/run.py
Signal-triggered shutdown paths updated to call exporter.stop(..., should_unregister=True), changing unregister behavior on signal-based shutdown without other control-flow changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant OS as OS Signal
  participant CLI as CLI Runner
  participant EXP as Exporter
  participant CTRL as Controller

  OS->>CLI: SIGHUP/SIGTERM
  CLI->>EXP: stop(wait_for_lease_exit=?, should_unregister=true)
  alt immediate stop (wait_for_lease_exit=false)
    EXP->>EXP: set _unregister = true
    EXP->>EXP: cancel tasks / cleanup
    opt registered && _unregister
      EXP->>CTRL: unregister()
      CTRL-->>EXP: ok
    end
    EXP-->>CLI: stopped
  else lease-exit path (wait_for_lease_exit=true)
    EXP->>EXP: wait for lease exit
    EXP->>EXP: stop(..., should_unregister=true)
    opt registered && _unregister
      EXP->>CTRL: unregister()
      CTRL-->>EXP: ok
    end
    EXP-->>CLI: stopped
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • mangelajo

Poem

I twitch my whiskers at the bell,
A tiny flag I tuck and tell.
Should I unhook from controller’s thread?
I nod, then hop to bed instead.
Thump—clean exit, carrot dream ahead. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary behavioral change of unregistering from the controller only on a proper exit, matching the PR’s main purpose of gating unregistration behind the new should_unregister flag without unnecessary detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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 and usage tips.

@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 26, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 8587858
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/68da2dee24beee0008c9d2c8
😎 Deploy Preview https://deploy-preview-659--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34ab330 and 9068ace.

📒 Files selected for processing (2)
  • packages/jumpstarter-cli/jumpstarter_cli/run.py (1 hunks)
  • packages/jumpstarter/jumpstarter/exporter/exporter.py (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: michalskrivanek
PR: jumpstarter-dev/jumpstarter#584
File: packages/jumpstarter/jumpstarter/client/grpc.py:38-54
Timestamp: 2025-08-18T07:13:37.619Z
Learning: User michalskrivanek prefers inline code over small helper function extractions when the abstraction doesn't significantly improve readability or reduce complexity. They value straightforward, readable code over reducing minor duplication.
🧬 Code graph analysis (1)
packages/jumpstarter-cli/jumpstarter_cli/run.py (1)
packages/jumpstarter/jumpstarter/exporter/exporter.py (1)
  • stop (46-61)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: e2e
🔇 Additional comments (3)
packages/jumpstarter-cli/jumpstarter_cli/run.py (1)

64-64: Confirm intent: unregister on all signals (not just SIGHUP).

You pass should_unregister=True for every signal, including SIGINT/SIGTERM/SIGQUIT. If that’s the intended “proper exit” definition, LGTM. If you only want unregister on specific signals, gate it accordingly.

packages/jumpstarter/jumpstarter/exporter/exporter.py (2)

69-85: Cleanup logic looks solid.

Conditional unregister + 10s timeout with shielded close is good for reliability.


205-207: Good: unregister only after lease exit path.

This ensures graceful SIGHUP flow: defer cancellation until not leased, then request unregister.

Comment thread packages/jumpstarter/jumpstarter/exporter/exporter.py Outdated
exceptions raised duing serve() and lease changes keep the exporter registered with controller to avoid quick online/offline transitions since the internal logic restarts the jumpstarter child process within few seconds. On termination signal the unregistration still happens as the parent process also terminates.
Note it still causes offline/online bounce if it is immediatelly restarted via systemd service for example.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/jumpstarter/jumpstarter/exporter/exporter.py (2)

46-52: Make stop() params keyword‑only and typed to avoid call‑site ambiguity.

Prevents accidental positional mix‑ups now that a second boolean was added.

Apply:

-    def stop(self, wait_for_lease_exit=False, should_unregister=False):
+    def stop(self, *, wait_for_lease_exit: bool = False, should_unregister: bool = False) -> None:

(Non‑breaking for current call sites that already use keywords.) Based on learnings.


69-85: Differentiate timeout vs error; clear state post‑unregister.

Two small tweaks improve observability and state hygiene:

  • Log when the 10s timeout triggers (distinct from exceptions).
  • Mark registered = False after a successful Unregister to avoid stale state if the instance is reused.

Apply:

-                        with move_on_after(10):  # 10 second timeout
+                        with move_on_after(10) as cs:  # 10s timeout
                             channel = await self.channel_factory()
                             try:
                                 controller = jumpstarter_pb2_grpc.ControllerServiceStub(channel)
                                 await controller.Unregister(
                                     jumpstarter_pb2.UnregisterRequest(
                                         reason="Exporter shutdown",
                                     )
                                 )
                                 logger.info("Controller unregistration completed successfully")
+                                self.registered = False
                             finally:
                                 with CancelScope(shield=True):
                                     await channel.close()
+                        if cs.cancel_called:
+                            logger.warning("Controller unregistration timed out after 10s")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9068ace and 8587858.

📒 Files selected for processing (2)
  • packages/jumpstarter-cli/jumpstarter_cli/run.py (1 hunks)
  • packages/jumpstarter/jumpstarter/exporter/exporter.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/jumpstarter-cli/jumpstarter_cli/run.py
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: michalskrivanek
PR: jumpstarter-dev/jumpstarter#584
File: packages/jumpstarter/jumpstarter/client/grpc.py:38-54
Timestamp: 2025-08-18T07:13:37.619Z
Learning: User michalskrivanek prefers inline code over small helper function extractions when the abstraction doesn't significantly improve readability or reduce complexity. They value straightforward, readable code over reducing minor duplication.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: e2e
🔇 Additional comments (3)
packages/jumpstarter/jumpstarter/exporter/exporter.py (3)

41-41: Explicit unregister gate — good change.

Private _unregister cleanly separates transient restarts from intentional shutdowns and prevents controller flapping.


56-58: Order of operations LGTM.

Setting _unregister before cancelling the task group ensures the intent survives cancellation.


206-207: All Exporter.stop calls explicitly use should_unregister; no positional booleans remain.

@mangelajo mangelajo merged commit 4d24a43 into jumpstarter-dev:main Sep 29, 2025
18 checks passed
@jumpstarter-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for release-0.7:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants