Skip to content

feat: propagate CancellationToken throughout the backend - #378

Merged
hhvrc merged 2 commits into
developfrom
feat/cancellation-token-propagation
Oct 16, 2026
Merged

hhvrc merged 2 commits into
developfrom
feat/cancellation-token-propagation

Conversation

@hhvrc

@hhvrc hhvrc commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Thread cancellation tokens from controllers, SignalR hubs, auth handlers,
the LiveControlGateway receive loop and cron jobs down into every service
and EF Core/HttpClient/HybridCache call that accepts one.

  • Services (device, OTA, configuration, control sender, webhook, device
    update, account, API token, session create/logout) take a token.
  • Hubs use Context.ConnectionAborted; auth handlers use RequestAborted.
  • Cron jobs use the host's ApplicationStopping token; Execute() keeps no
    parameters so Hangfire job signatures are unchanged.
  • Email outbox delivery stops on shutdown and always records a send's
    outcome once the email has gone out.
  • Add .editorconfig disabling the primary-constructor suggestion.

hhvrc added 2 commits October 16, 2026 18:26
Thread cancellation tokens from controllers, SignalR hubs, auth handlers,
the LiveControlGateway receive loop and cron jobs down into every service
and EF Core/HttpClient/HybridCache call that accepts one.

- Services (device, OTA, configuration, control sender, webhook, device
  update, account, API token, session create/logout) take a token.
- Hubs use Context.ConnectionAborted; auth handlers use RequestAborted.
- Cron jobs use the host's ApplicationStopping token; Execute() keeps no
  parameters so Hangfire job signatures are unchanged.
- Email outbox delivery stops on shutdown and always records a send's
  outcome once the email has gone out.
- Add .editorconfig disabling the primary-constructor suggestion.
…token-propagation

# Conflicts:
#	Common/Hubs/PublicShareHub.cs
#	Common/Services/ControlSender.cs
#	Common/Services/IControlSender.cs
@hhvrc
hhvrc requested review from LucHeart and a balanced review from Copilot October 16, 2026 16:35
@hhvrc hhvrc self-assigned this Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e4934e1f-e17a-4a24-a341-cb8946139d5e
📥 Commits

Reviewing files that changed from the base of the PR and between eed7798 and ab32f4e.

📒 Files selected for processing: 94
  • .editorconfig
  • API.IntegrationTests/Tests/AutomationTokenTests.cs
  • API/Controller/Account/Authenticated/ChangeEmail.cs
  • API/Controller/Account/Authenticated/ChangePassword.cs
  • API/Controller/Account/Authenticated/ChangeUsername.cs
  • API/Controller/Account/Authenticated/Deactivate.cs
  • API/Controller/Account/LoginV2.cs
  • API/Controller/Account/Logout.cs
  • API/Controller/Account/PasswordResetComplete.cs
  • API/Controller/Account/PasswordResetInitiateV2.cs
  • API/Controller/Admin/AutomationTokenList.cs
  • API/Controller/Admin/Configuration.cs
  • API/Controller/Admin/DeactivateUser.cs
  • API/Controller/Admin/DeleteUser.cs
  • API/Controller/Admin/EmailOutboxList.cs
  • API/Controller/Admin/EmailOutboxStats.cs
  • API/Controller/Admin/EmailProviderBlacklistList.cs
  • API/Controller/Admin/GetOnlineDevices.cs
  • API/Controller/Admin/GetUsers.cs
  • API/Controller/Admin/ReactivateUser.cs
  • API/Controller/Admin/SetUserPassword.cs
  • API/Controller/Admin/UserNameBlacklistAdd.cs
  • API/Controller/Admin/UserNameBlacklistList.cs
  • API/Controller/Admin/WebhookAdd.cs
  • API/Controller/Admin/WebhookList.cs
  • API/Controller/Admin/WebhookRemove.cs
  • API/Controller/Device/GetSelf.cs
  • API/Controller/Device/Pair.cs
  • API/Controller/Devices/DeviceOtaController.cs
  • API/Controller/Devices/DevicesController.cs
  • API/Controller/Devices/GetShockers.cs
  • API/Controller/OAuth/HandOff.cs
  • API/Controller/OAuth/SignupFinalize.cs
  • API/Controller/Public/PublicShareController.cs
  • API/Controller/Shares/DeleteShareCode.cs
  • API/Controller/Shares/LinkShareCode.cs
  • API/Controller/Shares/Links/AddShocker.cs
  • API/Controller/Shares/Links/CreatePublicShare.cs
  • API/Controller/Shares/Links/DeletePublicShare.cs
  • API/Controller/Shares/Links/EditShocker.cs
  • API/Controller/Shares/Links/PauseShocker.cs
  • API/Controller/Shares/Links/RemoveShocker.cs
  • API/Controller/Shares/UserShares/CreateShareInvite.cs
  • API/Controller/Shares/UserShares/Invites.cs
  • API/Controller/Shares/UserShares/PauseShockerShares.cs
  • API/Controller/Shares/UserShares/RemoveShockerShares.cs
  • API/Controller/Shares/UserShares/UpdateShockerShares.cs
  • API/Controller/Shockers/EditShocker.cs
  • API/Controller/Shockers/GetShockerById.cs
  • API/Controller/Shockers/GetShockerLogs.cs
  • API/Controller/Shockers/ListSharedShockers.cs
  • API/Controller/Shockers/PauseShocker.cs
  • API/Controller/Shockers/RegisterShocker.cs
  • API/Controller/Shockers/RemoveShocker.cs
  • API/Controller/Shockers/SendControl.cs
  • API/Controller/Shockers/ShockerShares.cs
  • API/Controller/Tokens/ReportTokens.cs
  • API/Controller/Tokens/Tokens.cs
  • API/Services/Account/AccountService.cs
  • API/Services/Account/IAccountService.cs
  • API/Services/DeviceUpdate/DeviceUpdateService.cs
  • API/Services/DeviceUpdate/IDeviceUpdateService.cs
  • API/Services/Token/ApiTokenService.cs
  • API/Services/Token/IApiTokenService.cs
  • Common/Authentication/AuthenticationHandlers/ApiTokenAuthentication.cs
  • Common/Authentication/AuthenticationHandlers/HubAuthentication.cs
  • Common/Authentication/AuthenticationHandlers/UserSessionAuthentication.cs
  • Common/Hubs/PublicShareHub.cs
  • Common/Hubs/UserHub.cs
  • Common/OpenShockControllerBase.cs
  • Common/Services/Configuration/ConfigurationService.cs
  • Common/Services/Configuration/IConfigurationService.cs
  • Common/Services/ControlSender.cs
  • Common/Services/Device/DeviceService.cs
  • Common/Services/Device/IDeviceService.cs
  • Common/Services/IControlSender.cs
  • Common/Services/Ota/IOtaService.cs
  • Common/Services/Ota/OtaService.cs
  • Common/Services/Session/ISessionService.cs
  • Common/Services/Session/SessionService.cs
  • Common/Services/Webhook/IWebhookService.cs
  • Common/Services/Webhook/WebhookService.cs
  • Cron/DashboardAdminAuth.cs
  • Cron/Jobs/ClearOldAuditLogsJob.cs
  • Cron/Jobs/ClearOldEmailChangesJob.cs
  • Cron/Jobs/ClearOldPasswordResetsJob.cs
  • Cron/Jobs/ClearOldShockerControlLogs.cs
  • Cron/Jobs/DeleteDeactivatedAccounts.cs
  • Cron/Jobs/DeleteExpiredAutomatedAccountsJob.cs
  • Cron/Jobs/EmailOutboxDeliveryJob.cs
  • Cron/Jobs/OtaTimeoutJob.cs
  • LiveControlGateway/Controllers/HubV1Controller.cs
  • LiveControlGateway/Controllers/HubV2Controller.cs
  • LiveControlGateway/Websocket/FlatbuffersWebsocketBaseController.cs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@hhvrc
hhvrc merged commit e0367b5 into develop Oct 16, 2026
25 checks passed
@hhvrc
hhvrc deleted the feat/cancellation-token-propagation branch October 16, 2026 18:08
hhvrc added a commit that referenced this pull request Nov 4, 2026
#378 threaded the request/socket CancellationToken into every write. A
client disconnect could then abort a flow halfway through: a commit could
succeed in Postgres while CommitAsync threw, which skipped the post-commit
work, and non-transactional sequences were left half-done.

Keep the token for reads, validation and Turnstile. Writes now run
uncancelled:

- ReportTokens: the token delete, report row and admin webhook can no
  longer be split, so a deletion is never left unrecorded.
- Logout: the session is always deleted. Before, a cancelled audit write
  left the session valid on the server.
- Session creation: the Login audit entry always follows the Redis
  insert. ISessionService / CreateSession no longer take a token
  (LoginV2, OAuth HandOff, SignupFinalize).
- Transactional services (Account, ApiToken, OAuthConnection,
  AutomationToken admin, CreateShareInvite, ControlSender): begin, save,
  commit and rollback no longer take the token, so post-commit work such
  as the session purge on deactivation and the outbox nudge still runs.
- AutomationTokenService: the use audit is no longer cancellable.
- ConfigurationService: the cache update after a DB save is no longer
  skipped, so config doesn't go stale.
- OtaService: hub status writes survive the hub disconnecting right after
  reporting.
- IDeviceUpdateService: dropped the token. These are post-write
  notifications.
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.

2 participants