[rubygems/rubygems] Set thread configurations inside block in the thread local manner

https://github.com/rubygems/rubygems/commit/965e54b8f1
This commit is contained in:
Nobuyoshi Nakada 2023-07-29 10:21:55 +09:00 committed by git
parent 0d86cc4caf
commit 67be453d9d
2 changed files with 12 additions and 14 deletions

View File

@ -33,17 +33,16 @@ module Gem::GemcutterUtilities
end
def self.listener_thread(host, server)
thread = Thread.new do
Thread.current[:otp] = new(host).wait_for_otp_code(server)
Thread.new do
thread = Thread.current
thread.abort_on_exception = true
thread.report_on_exception = false
thread[:otp] = new(host).wait_for_otp_code(server)
rescue Gem::WebauthnVerificationError => e
Thread.current[:error] = e
thread[:error] = e
ensure
server.close
end
thread.abort_on_exception = true
thread.report_on_exception = false
thread
end
def wait_for_otp_code(server)

View File

@ -32,15 +32,14 @@ module Gem::GemcutterUtilities
end
def self.poll_thread(options, host, webauthn_url, credentials)
thread = Thread.new do
Thread.current[:otp] = new(options, host).poll_for_otp(webauthn_url, credentials)
Thread.new do
thread = Thread.current
thread.abort_on_exception = true
thread.report_on_exception = false
thread[:otp] = new(options, host).poll_for_otp(webauthn_url, credentials)
rescue Gem::WebauthnVerificationError, Timeout::Error => e
Thread.current[:error] = e
thread[:error] = e
end
thread.abort_on_exception = true
thread.report_on_exception = false
thread
end
def poll_for_otp(webauthn_url, credentials)