User#ensure_rss_token may be run on a read-only secondary node
As seen in https://sentry.gitlap.com/gitlab/gitlab-geo-internal-develop-is/issues/35645/
PG::ReadOnlySqlTransaction: ERROR: cannot execute UPDATE in a read-only transaction
from peek/views/pg.rb:26:in `exec_prepared'
from peek/views/pg.rb:26:in `exec_prepared'
from active_record/connection_adapters/postgresql_adapter.rb:602:in `block in exec_cache'
from active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
from active_support/notifications/instrumenter.rb:20:in `instrument'
from active_record/connection_adapters/abstract_adapter.rb:478:in `log'
from active_record/connection_adapters/postgresql_adapter.rb:601:in `exec_cache'
from active_record/connection_adapters/postgresql_adapter.rb:585:in `execute_and_clear'
from active_record/connection_adapters/postgresql/database_statements.rb:173:in `exec_delete'
from active_record/connection_adapters/abstract/database_statements.rb:114:in `update'
from active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
from active_record/relation.rb:88:in `_update_record'
from active_record/persistence.rb:515:in `_update_record'
from config/initializers/active_record_locking.rb:16:in `_update_record'
from active_record/attribute_methods/dirty.rb:129:in `_update_record'
from active_record/callbacks.rb:310:in `block in _update_record'
from active_support/callbacks.rb:117:in `call'
from active_support/callbacks.rb:555:in `block (2 levels) in compile'
from active_support/callbacks.rb:505:in `call'
from active_support/callbacks.rb:92:in `__run_callbacks__'
from active_support/callbacks.rb:778:in `_run_update_callbacks'
from active_record/callbacks.rb:310:in `_update_record'
from active_record/timestamp.rb:70:in `_update_record'
from active_record/persistence.rb:504:in `create_or_update'
from active_record/callbacks.rb:302:in `block in create_or_update'
from active_support/callbacks.rb:117:in `call'
from active_support/callbacks.rb:555:in `block (2 levels) in compile'
from active_support/callbacks.rb:505:in `call'
from active_support/callbacks.rb:92:in `__run_callbacks__'
from active_support/callbacks.rb:778:in `_run_save_callbacks'
from active_record/callbacks.rb:302:in `create_or_update'
from active_record/persistence.rb:142:in `save!'
from active_record/validations.rb:43:in `save!'
from active_record/attribute_methods/dirty.rb:29:in `save!'
from active_record/transactions.rb:291:in `block in save!'
from active_record/transactions.rb:351:in `block in with_transaction_returning_status'
from active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
from active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
from active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
from active_record/transactions.rb:220:in `transaction'
from active_record/transactions.rb:348:in `with_transaction_returning_status'
from active_record/transactions.rb:291:in `save!'
from state_machines/integrations/active_record.rb:505:in `block in save!'
from state_machines/integrations/active_record.rb:520:in `block in around_save'
from state_machines/transition_collection.rb:150:in `block in run_actions'
from state_machines/transition_collection.rb:170:in `catch_exceptions'
from state_machines/transition_collection.rb:148:in `run_actions'
from state_machines/transition_collection.rb:133:in `run_callbacks'
from state_machines/transition_collection.rb:212:in `run_callbacks'
from state_machines/transition_collection.rb:63:in `block (2 levels) in perform'
from state_machines/transition_collection.rb:63:in `catch'
from state_machines/transition_collection.rb:63:in `block in perform'
from state_machines/transition_collection.rb:186:in `within_transaction'
from state_machines/transition_collection.rb:62:in `perform'
from state_machines/integrations/active_record.rb:520:in `around_save'
from state_machines/integrations/active_record.rb:505:in `save!'
from app/models/concerns/token_authenticatable.rb:53:in `block in add_authentication_token_field'
from app/models/concerns/token_authenticatable.rb:47:in `block in add_authentication_token_field'
from app/models/user.rb:1052:in `rss_token'
from active_support/core_ext/object/try.rb:77:in `public_send'
from active_support/core_ext/object/try.rb:77:in `try!'
from active_support/core_ext/object/try.rb:63:in `try'
from app/helpers/rss_helper.rb:3:in `rss_url_options'
from app/views/dashboard/projects/index.html.haml:6:in `block in _app_views_dashboard_projects_index_html_haml__1277709306543383271_70135987341360'
User#rss_token calls User#ensure_rss_token, which is not safe in the context of a GET request on a Geo secondary.
The comment on that method suggests that the code was added prior to the addition of background migrations; perhaps that's the best way forward here?
/assignee @to1ne