Repository navigation
fix(connections): keep channel state consistent across reconnect, disconnect and token refresh - #1815
Merged
Merged
Conversation
…connect and token refresh - guard token refresh writes with a compare-and-swap on the stored access token so a reconnect in between is not overwritten (Zalo's single-use refresh token would otherwise be burned) - restore or flag Inbox.status for orphan channels with no Connection row - release the channels quota unit only after the caller's transaction commits, and resolve the owner when refresh crons carry none - index connect_session target connection
…ota release - move accessTokenMatches from business/connection to packages/database so repositories and refresh handlers can use it without a cycle - add createPendingRelease/PendingQuotaReleaseRef and extract reconnectOrphanInbox, which re-consumes channel quota when reviving an orphan inbox whose unit was already released - update refresh handlers, disconnect actions and tests accordingly
… back usage with the tx An orphan inbox disconnected before disconnectReason existed had its quota unit released, so reviving it now consumes one again instead of bypassing the channel limit. resumeTenantSuspended also writes the workspace usage row on the caller's transaction so a reconnect rollback undoes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connection) now getInbox.statusrestored on reconnect and set toneeds_reauthwhen unhealthy, instead of staying out of sync.channelsquota unit is released only after the caller's transaction commits, and refresh crons with no owner resolve it from the workspace, so a later reconnect cannot consume a second unit.Changes
packages/business/src/connection/auth-cas.ts: compare-and-swapWHEREfragment on the stored access token, used by the per-channel services and refresh handlers inapps/worker/src/schedule/handlers/.packages/business/src/connection/state-service.ts:pendingRelease/runDisconnectInTransaction, orphan-inbox status mirroring, owner resolution in unhealthy marking.packages/connections: connect-session flow and Messenger teardown updates.apps/builder: connect flow, webhook routing, Instagram/WhatsApp disconnect actions.packages/database: index onconnect_sessiontarget connection (new migration, not applied automatically) and WhatsApp repository change.Test plan
db:migrate