fix: make handle_subscribe future Send by scoping RwLockReadGuard

This commit is contained in:
ospab 2026-05-27 23:38:32 +03:00
parent 3920665d89
commit d018d68b79
1 changed files with 14 additions and 8 deletions

View File

@ -757,20 +757,26 @@ async fn handle_reset_stats(
/// ///
/// GET /api/subscribe/{key} /// GET /api/subscribe/{key}
/// Response: JSON client config or ostp:// share link (via Accept header) /// Response: JSON client config or ostp:// share link (via Accept header)
async fn handle_subscribe( async fn handle_subscribe(
State(state): State<ApiState>, State(state): State<ApiState>,
Path(key): Path<String>, Path(key): Path<String>,
headers: axum::http::HeaderMap, headers: axum::http::HeaderMap,
) -> impl IntoResponse { ) -> axum::response::Response {
// Validate that the key exists use axum::response::IntoResponse;
// Validate that the key exists in a tightly scoped block to drop the guard
let key_exists = {
let keys = state.access_keys.read().unwrap(); let keys = state.access_keys.read().unwrap();
if !keys.contains_key(&key) { keys.contains_key(&key)
};
if !key_exists {
return (StatusCode::NOT_FOUND, Json(serde_json::json!({ return (StatusCode::NOT_FOUND, Json(serde_json::json!({
"ok": false, "ok": false,
"error": "invalid access key" "error": "invalid access key"
}))); }))).into_response();
} }
drop(keys);
let accept = headers.get("accept") let accept = headers.get("accept")
.and_then(|v| v.to_str().ok()) .and_then(|v| v.to_str().ok())
@ -791,7 +797,7 @@ async fn handle_subscribe(
return (StatusCode::OK, Json(serde_json::json!({ return (StatusCode::OK, Json(serde_json::json!({
"ok": true, "ok": true,
"data": link "data": link
}))); }))).into_response();
} }
// Default: return full client config JSON // Default: return full client config JSON
@ -822,7 +828,7 @@ async fn handle_subscribe(
(StatusCode::OK, Json(serde_json::json!({ (StatusCode::OK, Json(serde_json::json!({
"ok": true, "ok": true,
"data": config "data": config
}))) }))).into_response()
} }
// ── DNS API Handlers ────────────────────────────────────────────────────────── // ── DNS API Handlers ──────────────────────────────────────────────────────────