Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'gems/gitlab-utils/lib/gitlab/utils.rb')
-rw-r--r--gems/gitlab-utils/lib/gitlab/utils.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/gems/gitlab-utils/lib/gitlab/utils.rb b/gems/gitlab-utils/lib/gitlab/utils.rb
index b7cb63210ee..d5a514bfae8 100644
--- a/gems/gitlab-utils/lib/gitlab/utils.rb
+++ b/gems/gitlab-utils/lib/gitlab/utils.rb
@@ -261,6 +261,8 @@ module Gitlab
end
end
+ # Use this method to set the `restrict_within_concurrent_ruby` to `true` for the block.
+ # `raise_if_concurrent_ruby!` will use this flag to raise an error if it's set to `true`.
def restrict_within_concurrent_ruby
previous = Thread.current[:restrict_within_concurrent_ruby]
Thread.current[:restrict_within_concurrent_ruby] = true
@@ -270,6 +272,18 @@ module Gitlab
Thread.current[:restrict_within_concurrent_ruby] = previous
end
+ # Use this method to disable the `restrict_within_concurrent_ruby` for the block.
+ # It is mainly used to prevent infinite loop when `ConcurrentRubyThreadIsUsedError` is rescued and sent to Sentry.
+ # More info: https://gitlab.com/gitlab-org/gitlab/-/issues/432145#note_1671305713
+ def allow_within_concurrent_ruby
+ previous = Thread.current[:restrict_within_concurrent_ruby]
+ Thread.current[:restrict_within_concurrent_ruby] = false
+
+ yield
+ ensure
+ Thread.current[:restrict_within_concurrent_ruby] = previous
+ end
+
# Running external methods can allocate I/O bound resources (like PostgreSQL connection or Gitaly)
# This is forbidden when running within a concurrent Ruby thread, for example `async` HTTP requests
# provided by the `gitlab-http` gem.