From 67be453d9d1e94b104ba2f092d89c33efac2a2e2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 29 Jul 2023 10:21:55 +0900 Subject: [PATCH] [rubygems/rubygems] Set thread configurations inside block in the thread local manner https://github.com/rubygems/rubygems/commit/965e54b8f1 --- .../gemcutter_utilities/webauthn_listener.rb | 13 ++++++------- lib/rubygems/gemcutter_utilities/webauthn_poller.rb | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/rubygems/gemcutter_utilities/webauthn_listener.rb b/lib/rubygems/gemcutter_utilities/webauthn_listener.rb index ee3fc7bcab..bea9d9e397 100644 --- a/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +++ b/lib/rubygems/gemcutter_utilities/webauthn_listener.rb @@ -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) diff --git a/lib/rubygems/gemcutter_utilities/webauthn_poller.rb b/lib/rubygems/gemcutter_utilities/webauthn_poller.rb index 766b38584e..e7068605a4 100644 --- a/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +++ b/lib/rubygems/gemcutter_utilities/webauthn_poller.rb @@ -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)