[control] Share and token fixes: settle the epoch before minting, mint in its own task so a dropped client frees its key, token checks off the async threads, CLI refuses to run as another user than the state dir's owner

This commit is contained in:
2026-11-07 19:20:05 +01:00
parent 43918943da
commit 7d3af00720
6 changed files with 102 additions and 13 deletions
+26 -8
View File
@@ -997,14 +997,32 @@ pub async fn mint_share_link(
{
return Ok(replay(&st, s));
}
let out = mint_inner(&st, &actor, &hostname, body.value).await;
if let Some(k) = &key {
st.idem_finish(
k,
&fp,
out.as_ref().ok().map(|v| Stored::Json(201, v.clone())),
);
}
// In its own task: a client that goes away mid-request neither cancels the mint nor
// leaves its Idempotency-Key reserved.
let task = tokio::spawn({
let (st, actor, key, fp) = (st.clone(), actor.clone(), key.clone(), fp.clone());
let value = body.value;
async move {
let out = mint_inner(&st, &actor, &hostname, value).await;
if let Some(k) = &key {
st.idem_finish(
k,
&fp,
out.as_ref().ok().map(|v| Stored::Json(201, v.clone())),
);
}
out
}
});
let out = match task.await {
Ok(out) => out,
Err(e) => {
if let Some(k) = &key {
st.idem_finish(k, &fp, None);
}
Err(ApiError::internal(e.to_string()))
}
};
out.map(|v| json(StatusCode::CREATED, &v))
}