You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4fa1ee2
Browse filesBrowse the repository at this point in the historyBrowse files
fix(golang): a call whose context ends fails on its own, and leaves the client open
One encrypt.Client serves every request in a service, but a call whose
context was cancelled or passed its deadline closed it for all of them,
and so did the auth profile a client reads its tokens from. Both runtimes
are built with wazero's WithCloseOnContextDone, and every guest call ran
under the caller's context, so the runtime closed the module when that
context ended. Worse, the wait for the client's lock ignored the context:
a request that timed out in the queue behind a slow ZeroKMS round trip
reached the guest with a context already done, and wazero closed the
module before any guest code ran.
The fix keeps the caller's cancellation and takes it away from the
runtime. internal/guest gains three pieces, used by encrypt.Client and
auth.ProfileStore alike:
- Lock, a one-slot lock whose wait ends with the caller's context and
which refuses a context that has already ended, so a request that timed
out in the queue never starts. auth.Strategy's lock uses it too.
- Detach, the context a guest call runs under: the caller's values but
not its cancellation, so the runtime no longer closes the module when a
caller gives up.
- Caller, which the host functions use to reach the caller's context: a
ZeroKMS request, a CTS exchange or an OIDC provider call in flight is
cancelled, fails as a transport failure, and the guest returns through
its ordinary error path with its keys intact. The error matches both
the context's error and ErrTransport.
A backstop remains for a guest or host function that ignores
cancellation: Detach's context ends guest.StuckAfter (30s) after the
caller's, and the runtime then closes the module, as before. That close
now means a bug, never a closed browser tab.
TestInterruptedCallClosesTheClient pinned the old behaviour and is
replaced by tests of the new contract: a call cancelled during a ZeroKMS
request, during a token fetch, and during an auth strategy's exchange
leaves the client and the profile open; a call whose deadline passes in
the queue leaves without reaching the guest; a stuck call still closes
the client and the profile; and many callers cancelling at random share
one client without it closing.
Closes#1169
0 commit comments