{"record":{"id":"a742c9b39a63f973","repo":"plandex-ai/plandex","slug":"error-deleting-auth-token","errorCode":null,"errorMessage":"Error deleting auth token: ","messagePattern":"Error deleting auth token: ","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/sessions.go","lineNumber":264,"sourceCode":"\n\tlog.Println(\"Successfully signed in\")\n\n\tw.Write(bytes)\n}\n\nfunc SignOutHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for SignOutHandler\")\n\n\tauth := Authenticate(w, r, false)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\t_, err := db.Conn.Exec(\"UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1\", auth.AuthToken.TokenHash)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error deleting auth token: %v\\n\", err)\n\t\thttp.Error(w, \"Error deleting auth token: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\terr = ClearAuthCookieIfBrowser(w, r)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error clearing auth cookie: %v\\n\", err)\n\t\thttp.Error(w, \"Error clearing auth cookie: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\terr = ClearAccountFromCookies(w, r, auth.User.Id)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error clearing account from cookies: %v\\n\", err)\n\t\thttp.Error(w, \"Error clearing account from cookies: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/sessions.go#L246-L282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n_, err := db.Conn.Exec(\"UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1\", auth.AuthToken.TokenHash)\nif err != nil {\n\thttp.Error(w, \"Error deleting auth token: \"+err.Error(), http.StatusInternalServerError)\n\treturn\n}\n// after\n_, err := db.Conn.Exec(\"UPDATE auth_tokens SET deleted_at = NOW() WHERE token_hash = $1\", auth.AuthToken.TokenHash)\nif err != nil {\n\tlog.Printf(\"Error deleting auth token: %v\\n\", err)\n\tClearAuthCookieIfBrowser(w, r) // still clear client session\n\thttp.Error(w, \"Error deleting auth token\", http.StatusInternalServerError)\n\treturn\n}","handlingStrategy":"retry","validationCode":"// caller-side health probe before sign-out flows\nif err := db.Conn.Ping(ctx); err != nil {\n\treturn fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":"func isTransientDBError(err error) bool {\n\tvar pgErr *pgconn.PgError\n\tif errors.As(err, &pgErr) {\n\t\treturn pgErr.Code == \"57P01\" || pgErr.Code == \"53300\" // shutdown, too many connections\n\t}\n\treturn errors.Is(err, context.DeadlineExceeded) || errors.Is(err, io.EOF)\n}","tryCatchPattern":"_, err := db.Conn.Exec(updateTokenSQL, tokenHash)\nif err != nil && isTransientDBError(err) {\n\ttime.Sleep(backoff)\n\t_, err = db.Conn.Exec(updateTokenSQL, tokenHash)\n}\nif err != nil { return fmt.Errorf(\"error deleting auth token: %w\", err) }","preventionTips":["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"],"tags":["go","database","postgres","sql"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}