Downloading source code on Geo secondary attempts to write to the database
Summary
When trying to download the source code in a project page, the download fails because there's an audit event trying to be written to the database.
Steps to reproduce
- Create a new project
- Click download source code
Example Project
Reproduced on latest 12.7.5-ee version
What is the current bug behavior?
Downloading the source fails.
What is the expected correct behavior?
Downloading the source should succeed.
Relevant logs and/or screenshots
==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/root/repro-download/-/archive/master/repro-download-master.zip" for 127.0.0.1 at 2020-02-05 13:38:11 +0000
Processing by Projects::RepositoriesController#archive as ZIP
Parameters: {"namespace_id"=>"root", "project_id"=>"repro-download", "id"=>"master/repro-download-master"}
Completed 500 Internal Server Error in 344ms (ActiveRecord: 50.5ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::ReadOnlySqlTransaction: ERROR: cannot execute INSERT in a read-only transaction
: INSERT INTO "audit_events" ("author_id", "type", "entity_id", "entity_type", "details", "created_at", "updated_at") VALUES (1, 'SecurityEvent', 1, 'Project', '---
:custom_message: Repository Download Started
:author_name: Administrator
:target_id: root/repro-download
:target_type: Project
:target_details: root/repro-download
:ip_address: 127.0.0.1
:entity_path: root/repro-download
', '2020-02-05 13:38:12.036041', '2020-02-05 13:38:12.036041') RETURNING "id"):
app/services/audit_event_service.rb:47:in `log_security_event_to_database'
app/services/audit_event_service.rb:21:in `security_event'
ee/app/services/ee/audit_event_service.rb:100:in `security_event'
ee/app/controllers/ee/projects/repositories_controller.rb:19:in `log_audit_event'
ee/lib/gitlab/ip_address_state.rb:10:in `with'
ee/app/controllers/ee/application_controller.rb:43:in `set_current_ip_address'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:467:in `set_session_storage'
lib/gitlab/i18n.rb:55:in `with_locale'
lib/gitlab/i18n.rb:61:in `with_user_locale'
app/controllers/application_controller.rb:461:in `set_locale'
lib/gitlab/application_context.rb:18:in `with_context'
app/controllers/application_controller.rb:453:in `set_current_context'
lib/gitlab/error_tracking.rb:34:in `with_context'
app/controllers/application_controller.rb:545:in `sentry_context'
lib/gitlab/middleware/rails_queue_duration.rb:27:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:62:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
ee/lib/gitlab/jira/middleware.rb:19:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/multipart.rb:117:in `call'
lib/gitlab/middleware/read_only/controller.rb:52:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/middleware/request_context.rb:23:in `call'
config/initializers/fix_local_cache_middleware.rb:9:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:49:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Possible fixes
Prevent the SecurityEvent from writing to the DB on Geo secondaries.