ActiveRecord query timeout: ScheduleMigrateExternalDiffsWorker
Summary
Observed on gstg: https://sentry.gitlab.net/gitlab/staginggitlabcom/issues/1687958/?query=is%3Aunresolved
PG::QueryCanceled: ERROR: canceling statement due to statement timeout
from active_record/connection_adapters/postgresql_adapter.rb:675:in `exec_params'
# ...
from active_record/relation/calculations.rb:193:in `pluck'
from merge_request_diff.rb:109:in `ids_for_external_storage_migration'
from merge_requests/migrate_external_diffs_service.rb:10:in `enqueue!'
from schedule_migrate_external_diffs_worker.rb:17:in `block in perform'
It only seems to happen intermittently
Steps to reproduce
- Have a very large
merge_request_diffs
table where (almost?) all are migrated - Run:
MergeRequestDiff.ids_for_external_storage_migration
What is the current bug behavior?
Statement timeout
What is the expected correct behavior?
Query should complete successfully
Output of checks
This bug happens on GitLab.com
Possible fixes
We did carefully index this query. Why it's failing sometimes, but not other times, I'm unsure.
Edited by Nick Thomas