Skip to content

ZITADEL projection failure and Longhorn mount errors

Date: 2026-06-08 to 2026-06-09
Duration: ~8 hours
Severity: High — ZITADEL projections broken, VictoriaMetrics monitoring stack degraded
Environment: K3s 3-node cluster, ZITADEL v2.54.8, Longhorn storage, PostgreSQL 16, Ubuntu 22.04/24.04


Big Picture Summary

This incident involved three separate but related problems that all triggered on the same day:

Problem 1: ZITADEL Projections Broken

ZITADEL's projections.current_states table had corrupted indexes from zombie PostgreSQL transactions left by previous pod restarts. Every attempt to write projection state hung indefinitely on the corrupted index, causing a permanent projection already locked loop. The service remained functional (logins worked) but all background projection processing was broken.

Problem 2: Cross-node Pod Networking Broken

The ubuntu-24-04-lts-control-plane node had broken pod-to-service networking — TCP worked from the host but not from inside pod network namespaces. This caused ZITADEL pods scheduled on that node to fail connecting to the DB, which triggered the initial projection failures.

Problem 3: Longhorn Volumes Failing to Mount

multipathd was intercepting Longhorn's iSCSI block devices on ubuntu-24-04-lts-control-plane, preventing VictoriaMetrics pods from mounting their volumes. This was the same issue from the APISIX etcd incident (2026-05-27) that had not been applied cluster-wide.

How They Connected

DB pod restarted (NFS issue)
        │
        ▼
ZITADEL lost DB connections mid-transaction
        │
        ▼
Dead tuples accumulated in current_states indexes
        │
        ▼
ZITADEL rescheduled to broken node (ubuntu-24-04-lts-control-plane)
        │
        ▼
Pod networking broken → SASL auth timeouts
        │
        ▼
More zombie transactions → index corruption worsens
        │
        ▼
Every INSERT to current_states hangs → projection loop forever

Timeline

Time Event
T+0m ZITADEL projections reporting projection already locked for all projections
T+15m Identified DB connection timeouts: failed SASL auth (i/o timeout)
T+30m Confirmed cross-node pod networking broken on ubuntu-24-04-lts-control-plane
T+45m Pinned both ZITADEL and DB pods to ubuntu-mashup-gitlab-haproxy via nodeSelector
T+50m ZITADEL service restored — login returning 200 OK
T+60m ZITADEL_MASTERKEY env var accidentally dropped during kubectl edit — pod crashlooping
T+70m Restored ZITADEL_MASTERKEY — ZITADEL fully operational
T+90m Investigated VictoriaMetrics pods stuck in ContainerCreating
T+100m Identified Longhorn disk pressure on ubuntu-24-04-lts-control-plane (since Feb 2026)
T+110m Reduced Longhorn storageReserved from default to 10GB
T+120m Reduced Longhorn instance manager CPU from 12% to 5%
T+150m Identified multipathd intercepting Longhorn iSCSI devices
T+160m Applied multipath blacklist on all nodes — VictoriaMetrics pods recovered
T+180m Discovered ZITADEL_INSTANCE_ID mismatch (zitadel-single-1 vs 262269601956495363)
T+200m Fixed instance ID in both configmap and deployment env var
T+240m Discovered PostgreSQL connection pool leak — zombie transactions corrupting indexes
T+300m Added PostgreSQL timeouts and ZITADEL connection pool limits
T+360m Discovered current_states index corruption via PostgreSQL logs
T+420m Scaled ZITADEL to 0, truncated current_states, reindexed, restarted
T+430m Projections populating — count climbing from 0 to 60+ rows

Root Causes

Root Cause 1: current_states Index Corruption

This was the final root cause of the projection failure.

ZITADEL uses projections.current_states as a state tracker for all projections. The table uses two indexes: a primary key (projection_name, instance_id) and a secondary index on instance_id.

Through multiple DB pod restarts and ZITADEL pod restarts over time, many transactions were killed mid-flight. Each aborted transaction left dead tuples in the table and its indexes. Over time the indexes became inconsistent — the uniqueness checker was finding conflicting tuples that couldn't be resolved.

PostgreSQL logs revealed the exact failure:

ERROR: canceling statement due to statement timeout
CONTEXT: while inserting index tuple (1,21) in relation "current_states"

Every new INSERT hung inside the index update, causing: - Transaction never commits - Connection stays open with RowExclusiveLock - Next attempt finds the lock and also hangs - Infinite loop of zombie transactions

Root Cause 2: Cross-node Pod Networking Broken

The ZITADEL pod was scheduled on ubuntu-24-04-lts-control-plane while the DB pod was on ubuntu-mashup-gitlab-haproxy. Pod-to-service traffic across nodes was silently failing — TCP worked from the host but not from inside pod network namespaces.

Investigation showed kube-router was managing per-pod firewall rules but the flannel/iptables configuration on that node had issues causing pod egress to timeout.

Root Cause 3: multipathd Intercepting Longhorn iSCSI Devices

Longhorn presents virtual block devices via iSCSI (IET VIRTUAL-DISK). The multipathd daemon automatically claims any iSCSI device it detects:

Longhorn creates iSCSI device → /dev/sda (IET VIRTUAL-DISK)
        │
        ▼
multipathd sees /dev/sda → grabs it → creates /dev/mapper/mpatha
        │
        ▼
Longhorn CSI tries to mount /dev/sda
kernel: "Can't open blockdev" 

This was the same issue as the APISIX etcd incident (2026-05-27). The fix had only been applied to one node.

Contributing Factors

Factor Detail
ZITADEL_INSTANCE_ID mismatch Config had zitadel-single-1 but DB had 262269601956495363 — caused silent lock write failures for months
No PostgreSQL timeouts No statement_timeout or idle_in_transaction_session_timeout set — zombie transactions could live forever
No connection pool limits ZITADEL config had no MaxOpenConns — unconstrained connections amplified corruption
Longhorn disk pressure ubuntu-24-04-lts-control-plane had DiskPressure since February 2026 — storageReserved set too high
Longhorn instance manager CPU guaranteed-instance-manager-cpu at 12% (480m each) exhausted node CPU budget
kubectl edit danger Dropped ZITADEL_MASTERKEY env var during manual edit causing crashloop

Impact

Component Impact
ZITADEL Projection processing broken for ~8 hours — logins still worked but background processing degraded
VictoriaMetrics 3 pods stuck for ~2 hours — monitoring data gaps
Data loss None — eventstore.events2 intact throughout

Diagnosis Journey

Step 1: Check projection state

kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "SELECT count(*) FROM projections.current_states;"
# Result: 0 — projections not writing

Step 2: Check ZITADEL logs for real errors

kubectl logs -n default <zitadel-pod> | grep -i "error\|fatal" | grep -v "already locked" | tail -30
# Found: failed SASL auth (i/o timeout) → DB connection failing

Step 3: Check pod placement

kubectl get pods -n default -o wide | grep zitadel
# Found: ZITADEL on ubuntu-24-04-lts-control-plane, DB on ubuntu-mashup-gitlab-haproxy
# Different nodes → cross-node networking issue

Step 4: Check PostgreSQL logs (THE KEY STEP)

kubectl logs <zitadel-db-pod> -n default --tail=50
# Found: ERROR: canceling statement due to statement timeout
#        CONTEXT: while inserting index tuple (1,21) in relation "current_states"
# This revealed index corruption

Step 5: Check for zombie transactions

kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "SELECT pid, now() - query_start as duration, state, left(query, 60) as query 
   FROM pg_stat_activity 
   WHERE usename = 'zitadel_user' AND state = 'active'
   ORDER BY duration DESC;"
# Found: multiple INSERT INTO current_states running for 15+ HOURS

Step 6: Identify multipathd conflict

lsblk    # sda/sdb/sdc with mpath underneath
multipath -ll    # confirms IET VIRTUAL-DISK devices grabbed
dmesg | tail -20    # Can't open blockdev errors

Fix Applied

Fix 1 — Pin ZITADEL and DB pods to same node

kubectl patch deployment zitadel -n default -p \
  '{"spec":{"template":{"spec":{"nodeSelector":{"kubernetes.io/hostname":"ubuntu-mashup-gitlab-haproxy"}}}}}'

kubectl patch deployment zitadel-db -n default -p \
  '{"spec":{"template":{"spec":{"nodeSelector":{"kubernetes.io/hostname":"ubuntu-mashup-gitlab-haproxy"}}}}}'

Fix 2 — Restore ZITADEL_MASTERKEY (if accidentally dropped)

kubectl patch deployment zitadel -n default --type=json -p \
  '[{"op":"add","path":"/spec/template/spec/containers/0/env/0","value":{"name":"ZITADEL_MASTERKEY","valueFrom":{"secretKeyRef":{"name":"zitadel-secret-key","key":"masterkey"}}}}]'

Fix 3 — Fix ZITADEL Instance ID mismatch

# Get real instance ID from DB
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "SELECT id FROM projections.instances;"

# Update env var
kubectl set env deployment/zitadel -n default \
  ZITADEL_INSTANCE_ID=<real-instance-id>

# Update configmap
kubectl patch configmap zitadel-configmap -n default --type=merge -p \
  '{"data":{"zitadel-config.yaml":"...\nInstance:\n  ID: \"<real-instance-id>\"\n..."}}'

Fix 4 — Add PostgreSQL timeouts

kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "ALTER SYSTEM SET idle_in_transaction_session_timeout = '30s';"

kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "ALTER SYSTEM SET statement_timeout = '60s';"

kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "SELECT pg_reload_conf();"

Fix 5 — Add ZITADEL connection pool limits

Add to zitadel-config.yaml:

Database:
  postgres:
    Host: zitadel-db-cluster-ip-service
    Port: 5432
    Database: zitadel
    MaxOpenConns: 10
    MaxConnLifetime: 30m
    MaxConnIdleTime: 5m
    User:
      SSL:
        Mode: disable
    Admin:
      SSL:
        Mode: disable

Fix 6 — Truncate and reindex current_states (THE ACTUAL FIX)

# Stop ZITADEL completely
kubectl scale deployment zitadel -n default --replicas=0

# Kill all open connections
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename='zitadel_user';"

# Truncate the corrupted table (SAFE — no user data, rebuilt from eventstore)
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "TRUNCATE TABLE projections.current_states;"

# Rebuild the indexes
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "REINDEX TABLE projections.current_states;"

# Bring ZITADEL back
kubectl scale deployment zitadel -n default --replicas=1

Fix 7 — Blacklist Longhorn devices from multipathd (ALL NODES)

Run on every node in the cluster:

cat >> /etc/multipath.conf << 'EOF'

blacklist {
    device {
        vendor  "IET"
        product "VIRTUAL-DISK"
    }
}
EOF

multipath -f mpatha
multipath -f mpathb
multipath -f mpathc
systemctl restart multipathd

# Verify — should return empty
multipath -ll

Fix 8 — Longhorn disk and CPU settings

# Reduce storage reserved (node was in DiskPressure)
kubectl patch nodes.longhorn.io ubuntu-24-04-lts-control-plane \
  -n longhorn-system --type=json -p \
  '[{"op":"replace","path":"/spec/disks/default-disk-7e9f51643e9ceea3/storageReserved","value":10737418240}]'

# Reduce instance manager CPU (was causing CPU exhaustion)
kubectl patch setting.longhorn.io guaranteed-instance-manager-cpu \
  -n longhorn-system --type=merge -p '{"value":"5"}'

Recovery Steps

Complete ordered recovery procedure for future reference:

# === ZITADEL RECOVERY ===

# 1. Pin pods to same node
kubectl patch deployment zitadel -n default -p \
  '{"spec":{"template":{"spec":{"nodeSelector":{"kubernetes.io/hostname":"ubuntu-mashup-gitlab-haproxy"}}}}}'
kubectl patch deployment zitadel-db -n default -p \
  '{"spec":{"template":{"spec":{"nodeSelector":{"kubernetes.io/hostname":"ubuntu-mashup-gitlab-haproxy"}}}}}'

# 2. If projections still broken — check PostgreSQL logs first
kubectl logs <zitadel-db-pod> -n default --tail=50

# 3. If index corruption found — truncate and reindex
kubectl scale deployment zitadel -n default --replicas=0
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c \
  "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename='zitadel_user';"
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "TRUNCATE TABLE projections.current_states;"
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "REINDEX TABLE projections.current_states;"
kubectl scale deployment zitadel -n default --replicas=1

# 4. Verify health
curl -k https://iam.castis.io/debug/healthz
curl -k https://iam.castis.io/debug/validate

# === LONGHORN / MONITORING RECOVERY ===

# 5. Fix multipath on affected node
cat >> /etc/multipath.conf << 'EOF'
blacklist {
    device {
        vendor  "IET"
        product "VIRTUAL-DISK"
    }
}
EOF
multipath -f mpatha; multipath -f mpathb; multipath -f mpathc
systemctl restart multipathd

# 6. Delete stuck volumeattachments if pods remain stuck
kubectl get volumeattachment | grep <pvc-name>
kubectl delete volumeattachment <attachment-id>

# 7. Force delete stuck pods
kubectl delete pod <stuck-pod> -n monitoring --force --grace-period=0

# 8. Verify all monitoring pods running
kubectl get pods -n monitoring | grep -E "vmstorage|vmalertmanager|vmselect"

Prevention

1. Always check PostgreSQL logs when ZITADEL projections fail

kubectl logs <zitadel-db-pod> -n default --tail=50
The real error is in PostgreSQL logs, not ZITADEL logs.

2. Set PostgreSQL timeouts (already applied)

ALTER SYSTEM SET idle_in_transaction_session_timeout = '30s';
ALTER SYSTEM SET statement_timeout = '60s';
SELECT pg_reload_conf();

3. Set ZITADEL connection pool limits (already applied)

Database:
  postgres:
    MaxOpenConns: 10
    MaxConnLifetime: 30m
    MaxConnIdleTime: 5m

4. Apply multipath blacklist to ALL nodes (already applied)

Verify after any new node is added:

for node in ubuntu-24-04-lts-control-plane ubuntu-mashup-gitlab-haproxy worker-node-a; do
  echo "=== $node ==="
  ssh $node "grep -A4 'IET' /etc/multipath.conf"
done

5. Fix cross-node pod networking on ubuntu-24-04-lts-control-plane

Until fixed, cordon the node:

kubectl cordon ubuntu-24-04-lts-control-plane

6. Never use kubectl edit on production deployments

Use kubectl set env, kubectl patch, or kubectl set image instead. kubectl edit can silently drop env vars.

7. Verify ZITADEL_INSTANCE_ID matches DB after any migration

# DB value (ground truth)
kubectl exec -it <zitadel-db-pod> -n default -- \
  psql -U root -d zitadel -c "SELECT id FROM projections.instances;"

# Deployment value (must match)
kubectl describe deployment zitadel -n default | grep ZITADEL_INSTANCE_ID

8. Update ArgoCD manifests

All manual patches must be committed to git — nodeSelector, ZITADEL_MASTERKEY, instance ID, connection pool settings.

9. Monitor Longhorn disk usage

Alert when /var/lib/longhorn exceeds 70% on any node.


Lessons Learned

# Lesson
1 Check PostgreSQL logs first — kubectl logs <db-pod> shows the real error. ZITADEL logs only show symptoms
2 current_states is safe to truncate — it's a projection bookmark, not user data. Rebuilt automatically from eventstore.events2
3 Index corruption from aborted transactions is silent — no error in ZITADEL logs, only in PostgreSQL server logs
4 Set PostgreSQL timeouts on any DB used by ZITADEL — prevents zombie transactions from accumulating and corrupting indexes
5 Limit ZITADEL connection pool — unconstrained connections amplify corruption during restarts
6 multipathd conflicts with Longhorn on ALL nodes — fix must be applied cluster-wide when a new node is added
7 Cross-node pod networking can fail silently — TCP works from host but fails inside pod namespace
8 kubectl edit can drop env vars — always use kubectl patch or kubectl set for single-field changes
9 ZITADEL_INSTANCE_ID must match DB — it's a DB key, not a label. Set it from SELECT id FROM projections.instances
10 /debug/validate returning ok doesn't mean projections work — ZITADEL can serve requests from cache even with broken projections

Health Check Command

echo "=== ZITADEL HEALTH ===" && \
  curl -sk https://iam.castis.io/debug/healthz && echo "" && \
  curl -sk https://iam.castis.io/debug/validate && echo ""

echo "=== ZITADEL PROJECTIONS ===" && \
  kubectl exec -it $(kubectl get pod -n default -l app=zitadel-db -o jsonpath='{.items[0].metadata.name}') -n default -- \
  psql -U root -d zitadel -c "SELECT count(*) FROM projections.current_states;"

echo "=== ZITADEL DB CONNECTIONS ===" && \
  kubectl exec -it $(kubectl get pod -n default -l app=zitadel-db -o jsonpath='{.items[0].metadata.name}') -n default -- \
  psql -U root -d zitadel -c \
  "SELECT count(*), state FROM pg_stat_activity WHERE usename='zitadel_user' GROUP BY state;"

echo "=== ZOMBIE TRANSACTIONS ===" && \
  kubectl exec -it $(kubectl get pod -n default -l app=zitadel-db -o jsonpath='{.items[0].metadata.name}') -n default -- \
  psql -U root -d zitadel -c \
  "SELECT count(*) FROM pg_stat_activity WHERE usename='zitadel_user' AND now()-query_start > interval '1 minute';"

echo "=== MONITORING PODS ===" && \
  kubectl get pods -n monitoring | grep -E "vmstorage|vmalertmanager|vmselect" | grep -v Running

echo "=== LONGHORN NODES ===" && \
  kubectl get nodes.longhorn.io -n longhorn-system

echo "=== MULTIPATH (should be empty on all nodes) ===" && \
  for node in ubuntu-24-04-lts-control-plane ubuntu-mashup-gitlab-haproxy worker-node-a; do
    echo "--- $node ---"
    ssh $node "multipath -ll"
  done

echo "=== SERVICES ===" && \
  curl -sk https://iam.castis.io -o /dev/null -w "iam.castis.io: %{http_code}\n" && \
  curl -sk https://monitor.castis.io -o /dev/null -w "monitor.castis.io: %{http_code}\n"

Expected Healthy Output

ZITADEL healthz:        ok
ZITADEL validate:       "ok"
PROJECTIONS count:      60-80 rows
DB CONNECTIONS:         all idle or short-lived active
ZOMBIE TRANSACTIONS:    0
MONITORING PODS:        no output (all Running)
LONGHORN NODES:         all READY=True SCHEDULABLE=True
MULTIPATH:              empty on all nodes
SERVICES:               all 200 or 302

Incident resolved by: Manual diagnosis and fix
Total recovery time: ~8 hours
Data loss: None
Authored: 2026-06-09