Transport reuse and authorization state should have different lifetimes
A server may serve several application users or use more than one authorized account connection. Connection pooling does not require a global variable containing whichever bearer token was assigned most recently. Keep secret lookup and action ownership explicit. This is a design rule for your application; it does not change AISwapLab's account ownership checks or make multiple keys into independent balances.
What to do next
- 01
Remove mutable request defaults
Review the HTTP wrapper for shared Authorization assignments, reused mutable header objects and interceptors that read changing global state. Construct a fresh request header set from the action's authorized connection. Keep secret values out of task payloads and logs where possible. Pool sockets through the library's supported mechanism without attaching tenant identity to a shared mutable configuration object.
- 02
Bind credentials to the action context
Resolve the permitted connection from authenticated application ownership, not from a browser-supplied account label. Pass an immutable reference to the server-side secret provider and build headers immediately for that request. Do not let another asynchronous callback replace that reference while the request is queued. If credential rotation occurs, define the intended lookup behavior without changing which account the action belongs to.
- 03
Prove isolation under interleaving
Use two synthetic connection identities and a local capture server. Pause request A after construction, construct B, then release both in a controlled order. Assert that each request carries only its expected dummy token and action identifier. Repeat across the wrapper's retry and error paths without real provider calls. A sequential happy-path test cannot expose the shared-default race you are trying to prevent.
A concrete example
Illustrative example: a global client previously set a default bearer before every call. A deterministic test shows B overwriting A's token before A sends. Replacing that mutation with per-request headers preserves the shared connection pool while each captured request retains the correct synthetic credential.
Before you call it ready
- Header objects are request-scoped.
- Connection ownership comes from trusted context.
- Concurrent tests inspect the actual emitted headers.
When to stop or choose another method
Stop multi-connection dispatch if you cannot establish credential isolation. Freeze new commands, investigate without logging secrets and reconcile affected actions; do not assume upstream ownership errors will safely catch every wrong-account request.
