Server-side flow lifespan versus client-side context deadline for Ory Kratos self-service flows
0 reputation · 12 Oct 2023, 14:18 UTC
0 reputation · 12 Oct 2023, 14:18 UTC
Bound how long a caller can remain inside an Ory Kratos self-service login or registration flow without leaving the caller aborted while the server still holds a valid flow ID.
Kratos invalidates a flow when its server-side lifespan ends, but a Go client context deadline only aborts the outgoing HTTP request. The flow can remain valid server-side until the lifespan expires, the user completes it, or it is abandoned. Lifespan configuration keys differ between Kratos versions and Ory Network, so the deployed release determines which key applies.
Should the application enforce flow duration with the server-side lifespan, a client-side Go context deadline, or both? When a client deadline expires, should the application treat the existing Ory flow as expired, reusable, or otherwise reconcile it with server state?
Use both, but for different purposes. The server-side flow lifespan is authoritative for whether a Kratos self-service flow ID is still valid. A Go context deadline only cancels the client's outgoing HTTP request; it does not tell Kratos to expire the flow. When the deadline expires, treat the flow as potentially reusable, not expired. Let the caller submit the same flow ID again unless Kratos rejects it, the lifespan ends, or the flow is already completed.
Likely explanation: the application is treating client request cancellation as server-side flow expiry. Because a Go context deadline cancels only the client side of the HTTP call, Kratos has no visibility into it and keeps the flow alive until its configured lifespan ends.
Confirmed facts: Kratos invalidates a self-service flow when its server-side lifespan ends, when the flow is completed, or when the server otherwise invalidates it. A completed or already-consumed flow cannot be reused even if lifespan remains. Configuration keys and defaults differ between self-hosted Kratos releases and Ory Network, so the deployed release determines which key applies.
Create a flow, cancel the client request with a short Go context deadline, then submit the same flow ID before the server lifespan elapses. Observe whether Kratos accepts or rejects it. Repeat across deployed Kratos versions if more than one release is in use.
Missing diagnostic detail: Are you running self-hosted Kratos or Ory Network, and which Kratos version? This determines the lifespan configuration key to verify.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.