{"record":{"id":"48f8b806d32f43ce","repo":"LemmyNet/lemmy","slug":"err-getting-id-e","errorCode":null,"errorMessage":"err getting id: {e:?}","messagePattern":"err getting id: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/apub/send/src/util.rs","lineNumber":214,"sourceCode":"/// return the most current activity id (with 1 second cache)\npub(crate) async fn get_latest_activity_id(pool: &mut DbPool<'_>) -> Result<Option<ActivityId>> {\n  static CACHE: LazyLock<Cache<(), Option<ActivityId>>> = LazyLock::new(|| {\n    Cache::builder()\n      .time_to_live(*CACHE_DURATION_LATEST_ID)\n      .build()\n  });\n  CACHE\n    .try_get_with((), async {\n      use lemmy_db_schema_file::schema::sent_activity::dsl::{id, sent_activity};\n      let conn = &mut get_conn(pool).await?;\n      let latest_id: Option<ActivityId> = sent_activity\n        .select(diesel::dsl::max(id))\n        .get_result(conn)\n        .await?;\n      anyhow::Result::<_, anyhow::Error>::Ok(latest_id)\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"err getting id: {e:?}\"))\n}\n\n/// the domain name is needed for logging, pass it to the stats printer so it doesn't need to look\n/// up the domain itself\n#[derive(Debug)]\npub(crate) struct FederationQueueStateWithDomain {\n  pub domain: String,\n  pub state: FederationQueueState,\n}\n","sourceCodeStart":196,"sourceCodeEnd":224,"githubUrl":"https://github.com/LemmyNet/lemmy/blob/439734dd638a2c06a2f907beab7dcf4646e88f86/crates/apub/send/src/util.rs#L196-L224","documentation":"get_latest_activity_id wraps failures of the `SELECT max(id)` query on sent_activities into this anyhow error. Callers use the latest id to compute the next id to send, so this represents a failure of the cheap lookup query, not of sending itself.","triggerScenarios":"Any DB error while running the max(id) query against sent_activities — connection loss, pool exhaustion, permission problems, or the table being unavailable/locked (e.g. during migration).","commonSituations":"Database restart or failover while the federation worker is running; migrations locking sent_activities; connection pool exhaustion under heavy federation load.","solutions":["Check the inner debug error for the underlying diesel/DB cause","Verify database connectivity and connection pool configuration","Ensure schema migrations completed so sent_activities is queryable","Restart/retry the federation worker once the DB is healthy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"loop {\n  match get_latest_activity_id(pool).await {\n    Ok(id) => break id,\n    Err(e) if is_transient(&e) => { sleep(backoff()).await; }\n    Err(e) => return Err(e),\n  }\n}","preventionTips":["Retry transient DB failures with backoff","Ensure migrations finish before workers query sent_activities","Size the connection pool for all concurrent federation workers"],"tags":["database","diesel","federation","query"],"backgroundTag":"sql-query-failed","analyzedSha":"439734dd638a2c06a2f907beab7dcf4646e88f86","analyzedAt":"2026-09-06T11:28:35.035Z","contentChangedAt":"2026-09-06T11:28:35.035Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}