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
- Read the logged 'Error deleting auth token: ...' text to identify the driver error (connection refused vs SQL error)
- Verify connectivity to Postgres and that the auth_tokens table plus deleted_at column exist (run migrations)
- Check connection-pool settings and Postgres max_connections under load
- 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
- Retry transient DB errors (connection reset, too many connections) with backoff
- Keep migrations current so auth_tokens and deleted_at always exist
- Set sane pool sizes below Postgres max_connections
- On sign-out, clear client cookies even if the server-side delete fails
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
- Error getting org user config:
- error adding plan context tokens: %v
- error adding org member: %v
- error listing org roles: %v
- error adding org user: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/a742c9b39a63f973.
Report an issue: GitHub.