plandex-ai/plandex · error · http

Error deleting auth token:

Error message

Error deleting auth token: 

What it means

SignOutHandler fails at app/server/handlers/sessions.go:260-265 when the SQL UPDATE "UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1" against db.Conn returns an error. This soft-deletes the auth token to invalidate the session. The error comes from the pgx/database layer: connection loss, syntax/constraint issues, or driver errors.

Source

Thrown at app/server/handlers/sessions.go:264

	log.Println("Successfully signed in")

	w.Write(bytes)
}

func SignOutHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received request for SignOutHandler")

	auth := Authenticate(w, r, false)
	if auth == nil {
		return
	}

	_, err := db.Conn.Exec("UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1", auth.AuthToken.TokenHash)

	if err != nil {
		log.Printf("Error deleting auth token: %v\n", err)
		http.Error(w, "Error deleting auth token: "+err.Error(), http.StatusInternalServerError)
		return
	}

	err = ClearAuthCookieIfBrowser(w, r)

	if err != nil {
		log.Printf("Error clearing auth cookie: %v\n", err)
		http.Error(w, "Error clearing auth cookie: "+err.Error(), http.StatusInternalServerError)
		return
	}

	err = ClearAccountFromCookies(w, r, auth.User.Id)

	if err != nil {
		log.Printf("Error clearing account from cookies: %v\n", err)
		http.Error(w, "Error clearing account from cookies: "+err.Error(), http.StatusInternalServerError)
		return
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the logged 'Error deleting auth token: ...' text to identify the driver error (connection refused vs SQL error)
  2. Verify connectivity to Postgres and that the auth_tokens table plus deleted_at column exist (run migrations)
  3. Check connection-pool settings and Postgres max_connections under load
  4. Consider proceeding with sign-out (clearing cookies) even if the token update fails, so the user is not stuck

Example fix

// before
_, err := db.Conn.Exec("UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1", auth.AuthToken.TokenHash)
if err != nil {
	http.Error(w, "Error deleting auth token: "+err.Error(), http.StatusInternalServerError)
	return
}
// after
_, err := db.Conn.Exec("UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1", auth.AuthToken.TokenHash)
if err != nil {
	log.Printf("Error deleting auth token: %v\n", err)
	ClearAuthCookieIfBrowser(w, r) // still clear client session
	http.Error(w, "Error deleting auth token", http.StatusInternalServerError)
	return
}
Defensive patterns

Strategy: retry

Validate before calling

// caller-side health probe before sign-out flows
if err := db.Conn.Ping(ctx); err != nil {
	return fmt.Errorf("database unavailable: %w", err)
}

Type guard

func isTransientDBError(err error) bool {
	var pgErr *pgconn.PgError
	if errors.As(err, &pgErr) {
		return pgErr.Code == "57P01" || pgErr.Code == "53300" // shutdown, too many connections
	}
	return errors.Is(err, context.DeadlineExceeded) || errors.Is(err, io.EOF)
}

Try / catch

_, err := db.Conn.Exec(updateTokenSQL, tokenHash)
if err != nil && isTransientDBError(err) {
	time.Sleep(backoff)
	_, err = db.Conn.Exec(updateTokenSQL, tokenHash)
}
if err != nil { return fmt.Errorf("error deleting auth token: %w", err) }

Prevention

When it happens

Trigger: POST to the sign-out endpoint while the database is unreachable, the connection pool is exhausted, the auth_tokens table is missing/locked, or the TokenHash value triggers a driver encoding error.

Common situations: Database restarted or failing over, max_connections exhausted under load, migration not applied so auth_tokens/deleted_at column is absent, or network partition between app and Postgres.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/a742c9b39a63f973. Report an issue: GitHub.