summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-04-02 12:08:39 +0200
committerJean Boussier <[email protected]>2025-04-02 13:24:22 +0200
commit580aa60051773e3512121088eb8ebaee8ce605ea (patch)
tree9e36b3e1444278dd1bb2e043496288d66636ca0e /ext
parent43ee4a50d91652c0909b97fe7195af8e87600971 (diff)
Improve backtrace of errors raised by `Socket.tcp_with_fast_fallback`
[Bug #21211] Socket errors raised from background threads are hard to track down because their backtrace starts from the spawned thread. To solve this we can raise a new error with the old one as `cause`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13041
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/lib/socket.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index ae73b8799e..60dd45bd4f 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -693,6 +693,7 @@ class Socket < BasicSocket
connection_attempt_delay_expires_at = nil
user_specified_connect_timeout_at = nil
last_error = nil
+ last_error_from_thread = false
if resolving_family_names.size == 1
family_name = resolving_family_names.first
@@ -865,6 +866,7 @@ class Socket < BasicSocket
other = family_name == :ipv6 ? :ipv4 : :ipv6
if !resolution_store.resolved?(other) || !resolution_store.resolved_successfully?(other)
last_error = result
+ last_error_from_thread = true
end
end
else
@@ -885,7 +887,11 @@ class Socket < BasicSocket
if resolution_store.empty_addrinfos?
if connecting_sockets.empty? && resolution_store.resolved_all_families?
- raise last_error
+ if last_error_from_thread
+ raise last_error.class, last_error.message, cause: last_error
+ else
+ raise last_error
+ end
end
if (expired?(now, user_specified_resolv_timeout_at) || resolution_store.resolved_all_families?) &&