Fix exclusive lease usage in transaction for app/services/users/activity_service.rb
See original issue in #440368 (closed)
Problem: Fails spec/features/admin/admin_jobs_spec.rb
system test. This infradev issue was created for further investigation if https://gitlab.com/gitlab-org/gitlab/-/blob/ea71b210ca72ab6a061ffb3df09ed03b50e231c8/app/services/users/activity_service.rb#L38 shows up in production.
The stack trace can be obtained from the exceptions_json.log
file of https://gitlab.com/gitlab-org/gitlab/-/jobs/6156345379. Attached here: exceptions_json__2_.log
Exclusive lease cannot be obtained within a transaction as it could lead to idle transactions."
"lib/gitlab/exclusive_lease.rb:128:in `report_lock_attempt_inside_transaction'"
"lib/gitlab/exclusive_lease.rb:117:in `try_obtain'"
"app/services/users/activity_service.rb:36:in `record_activity'"
"app/services/users/activity_service.rb:22:in `block in execute'"
"app/services/users/activity_service.rb:22:in `execute'"
"app/controllers/graphql_controller.rb:171:in `set_user_last_activity'"
"ee/lib/gitlab/ip_address_state.rb:10:in `with'"
"ee/app/controllers/ee/application_controller.rb:45:in `set_current_ip_address'"
"lib/gitlab/auth/current_user_mode.rb:78:in `with_current_admin'"
"app/controllers/application_controller.rb:471:in `set_current_admin'"
"lib/gitlab/session.rb:11:in `with_session'"
"app/controllers/application_controller.rb:459:in `set_session_storage'"
"lib/gitlab/i18n.rb:114:in `with_locale'"
"lib/gitlab/i18n.rb:120:in `with_user_locale'"
"app/controllers/application_controller.rb:450:in `set_locale'"
"app/controllers/application_controller.rb:443:in `set_current_context'"
"lib/gitlab/middleware/memory_report.rb:13:in `call'"
"lib/gitlab/middleware/speedscope.rb:13:in `call'"
"lib/gitlab/query_limiting/middleware.rb:17:in `block in call'"
"lib/gitlab/query_limiting/transaction.rb:45:in `run'"
"lib/gitlab/query_limiting/middleware.rb:16:in `call'"
"lib/gitlab/middleware/go.rb:20:in `call'"
"lib/gitlab/etag_caching/middleware.rb:21:in `call'"
"lib/gitlab/middleware/query_analyzer.rb:11:in `block in call'"
"lib/gitlab/database/query_analyzer.rb:40:in `within'"
"lib/gitlab/middleware/query_analyzer.rb:11:in `call'"
"lib/gitlab/middleware/multipart.rb:173:in `call'"
"lib/gitlab/middleware/read_only/controller.rb:50:in `call'"
"lib/gitlab/middleware/read_only.rb:18:in `call'"
"lib/gitlab/middleware/unauthenticated_session_expiry.rb:18:in `call'"
"lib/gitlab/middleware/same_site_cookies.rb:27:in `call'"
"lib/gitlab/middleware/path_traversal_check.rb:45:in `call'"
"lib/gitlab/middleware/handle_malformed_strings.rb:21:in `call'"
"lib/gitlab/middleware/basic_health_check.rb:25:in `call'"
"lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call'"
"lib/gitlab/middleware/request_context.rb:15:in `call'"
"lib/gitlab/middleware/webhook_recursion_detection.rb:15:in `call'"
"config/initializers/fix_local_cache_middleware.rb:11:in `call'"
"lib/gitlab/middleware/compressed_json.rb:44:in `call'"
"lib/gitlab/middleware/static.rb:11:in `call'"
"lib/gitlab/testing/clear_process_memory_cache_middleware.rb:13:in `call'"
"lib/gitlab/testing/request_inspector_middleware.rb:35:in `call'"
"lib/gitlab/testing/robots_blocker_middleware.rb:30:in `call'"
"lib/gitlab/testing/request_blocker_middleware.rb:47:in `call'"
"lib/gitlab/middleware/rack_multipart_tempfile_factory.rb:19:in `call'"
"lib/gitlab/middleware/sidekiq_web_static.rb:20:in `call'"
"lib/gitlab/metrics/requests_rack_middleware.rb:79:in `call'
Edited by Sylvester Chin