Repository navigation
fix: keep the websocket client attached to a living AuthorizedApiContext - #207
Merged
Merged
Conversation
The websocket client holds one context to refetch a decoupled operation status with after an interrupted connection. Every context attached itself in its constructor, so each `createChildContext()` took the binding over - and a child is typically created per request and destroyed right after. The client was therefore left pointing at a destroyed context, whose requests reject with `BrokerizeAbortError` since 1.12.0, which only ever got logged: after a reconnect during a decoupled authorization, no further status updates arrived. Now the first context attaches and keeps the client, so children leave it alone, and a context detaches itself when it is destroyed instead of leaving a dead reference behind. Fixes #206 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #206.
The problem
AuthorizedApiContextattached itself to the websocket client in its constructor, unconditionally. A child context is constructed with its parent's shared_wsClient, so everycreateChildContext()quietly took the binding over — and children are commonly created per request and destroyed right after. The client was therefore left holding a destroyed context.That context has exactly one job: refetching the status of a decoupled operation after an interrupted connection. Since 1.12.0 a request on a destroyed context rejects with
BrokerizeAbortError, and the rejection is only logged, so the symptom was silent — after a reconnect during a decoupled authorization, no further status updates arrived.The fix
The binding now follows the lifetime of the client rather than the construction order:
destroy()if it is the attached one, so a later context can take over instead of a dead reference being left behind._setAuthorizedApiContextacceptsnullfor that, and_getAuthorizedApiContextwas added as its counterpart. Both are internal (underscore-prefixed) and do not show up in the API report. A websocket client that does not implement them — an application may pass its own — is handled as before.Tests
test/authorizedApiContext.test.jscovers the child-context case, the handover after a destroy, and a client without the binding methods. Verified that the first two fail onmainand pass with this change.🤖 Generated with Claude Code