block/buzz · critical · anyhow::Error

Failed to ensure deployment community (required when…

Error message

Failed to ensure deployment community (required when BUZZ_REQUIRE_RELAY_MEMBERSHIP=true): {e}

What it means

Fatal startup error: db.ensure_configured_community(&host) — the idempotent call that creates-or-fetches the deployment's own community — failed while BUZZ_REQUIRE_RELAY_MEMBERSHIP=true. The community row is the anchor for all membership writes, so the relay refuses to start; without enforcement the same failure is only logged.

Solutions

  1. Read the {e} detail — it distinguishes connectivity (retry) from permissions/schema (fix)
  2. Confirm migrations are applied and the DB role can INSERT/UPDATE the community tables
  3. If transient, restart the relay once Postgres is stably healthy
  4. Add a startup ordering gate (depends_on healthcheck / readiness init container) between Postgres and the relay
Defensive patterns

Strategy: retry

Validate before calling

# Boot gate: require Postgres healthy before the relay starts
# (same psql 'select 1' loop as error 43).

Try / catch

// Supervisor: retry relay startup with backoff while the error string starts
// with "Failed to ensure deployment community" and Postgres logs show a
// transient failure; halt for permission/schema errors.

Prevention

When it happens

Trigger: Any DB-level failure during the ensure-community upsert: transient connection drop right after the initial pool connect, permission denied on the communities table for the relay DB user, or a constraint/catalog problem (e.g. migrations not fully applied).

Common situations: Postgres restarting at the same moment as the relay; a least-privilege DB role missing INSERT/UPDATE on the community tables; pointing the relay at a database that was created without running migrations.

Related errors


AI-assisted analysis of block/buzz@ef2aa1ae38 (2026-08-20). Data as JSON: /api/errors/76086e09ce0f1315. Report an issue: GitHub.

Appendix: source

Thrown at crates/buzz-relay/src/main.rs:373

                    "Cannot derive a community host from BUZZ_RELAY_URL ({:?}); a resolvable host is required when BUZZ_REQUIRE_RELAY_MEMBERSHIP=true",
                    config.relay_url
                ));
            }
            error!(
                relay_url = %config.relay_url,
                "Could not derive a community host from relay_url; skipping membership backfill/bootstrap (non-fatal, membership not required)"
            );
            None
        } else {
            match db.ensure_configured_community_for_bootstrap(&host).await {
                Ok(record) => {
                    info!(host = %record.host, community = %record.id, "Deployment community ensured");
                    Some(record.id)
                }
                Err(e) => {
                    if config.require_relay_membership {
                        error!("Fatal: failed to ensure deployment community with membership enforcement enabled: {e}");
                        return Err(anyhow::anyhow!(
                            "Failed to ensure deployment community (required when BUZZ_REQUIRE_RELAY_MEMBERSHIP=true): {e}"
                        ));
                    }
                    error!("Failed to ensure deployment community (non-fatal, membership not required): {e}");
                    None
                }
            }
        }
    };

    // NIP-43: migrate any existing pubkey_allowlist entries to relay_members.
    // Idempotent — safe to run every startup. Must run before bootstrap_owner
    // so that existing allowlist users become relay members before the owner
    // is promoted (otherwise enabling membership locks everyone out).
    if let Some(community) = deployment_community {
        match db.backfill_from_allowlist(community).await {
            Ok(0) => {}
            Ok(n) => info!("Backfilled {n} pubkey_allowlist entries into relay_members"),

View on GitHub (pinned to ef2aa1ae38)