#1972·ntfy

[auth] Valid bearer token intermittently returns 401 after a successful auth (last_access reload wedge; up to 80+ min under active use)

Author: Jetty099Created Sep 26, 2026Updated Sep 26, 2026
Labels🪲 bug

Describe the bug

On ntfy 2.27.0, a valid bearer token intermittently returns 401 unauthenticated shortly after a successful authentication — and the wedge persists far longer than a reload cycle when the user stays active.

Observed behavior (measured twice, 2026-09-25/26, self-hosted Docker, SQLite user.db):

  1. Token posts successfully (200) to a restricted topic.
  2. Every subsequent request with the same correct token gets 401 {"code":40101,"http":401,"error":"unauthenticated"}.
  3. On a quiet user the wedge self-healed after ~4–14 minutes (single post 14 min after the last write got 200 again).
  4. Under continuous activity (polling ~every 20 s on a topic the token owns), the wedge did not heal for 80+ minutes — 240 consecutive attempts, all 401. Any successful auth re-triggers the state.

Evidence it is not a client/IP problem:

  • Same token, seconds apart, from two different clients/hosts (one on server localhost:8085, one over LAN) — both got 401 simultaneously ⇒ server-side state, not per-visitor.
  • With NTFY_DEBUG=true, the failing requests log Authentication failed (error=unauthenticated) while visitor_auth_attempts_remaining stays near its max (30) — so it is not the per-visitor auth-attempt throttle.
  • The ntfy token list view and the SQLite DB both show the token present with last_access updated, so the DB layer accepts it; the in-memory layer briefly does not.
  • A lone successful post re-opens the wedge — consistent with "each successful auth writes last_access to user.db; the user manager notices the mtime change and performs an async reload; requests landing around/after that reload are answered 401 despite a valid token."

To reproduce:

  • Serve ntfy 2.27.0 with auth-file (SQLite), auth-default-access: deny-all, one token on one topic.
  • Post a message with the token until you get a 200, then keep posting every ~20 s (or hammer a topic the token owns).
  • Watch for a window where the identical, correct token returns 401 for many minutes; it clears after a period with no writes touching that user, and re-appears after the next success.

Workaround (operator-side):

Escalating retry with gaps (10 s / 90 s / 8 min). Retries shorter than ~1 minute just re-enter the wedge, so short immediate retries make it worse.

Versions

  • ntfy 2.27.0 (also observed after a clean container restart, same image, so it is not a stale-startup state)
  • Docker, Linux amd64 host, SQLite auth DB, behind reverse proxy (behind-proxy: true)

Notes for maintainers

  • The last_access write-back + mtime-triggered async user reload path is the leading suspect.
  • If the wedge is meant to be short-lived, consecutive activity extending it to 80+ minutes suggests the reload/invalidation state is re-entered by each successful auth rather than converging.
  • Happy to provide full debug logs or host a reproduction container if useful.