Project

General

Profile

Actions

Bug #21211

closed

Incomplete Backtrace for Socket Errors in Ruby 3.4+

Added by ioquatix (Samuel Williams) 23 days ago. Updated 10 days ago.


Description

When invoking Socket.tcp with an invalid hostname (e.g., "foo.bar") in Ruby 3.4, the error raised does not provide a complete backtrace indicating the original application code that made the call. This behavior differs from Ruby 3.3 where the backtrace includes the relevant context.

Steps to Reproduce:

Run the following code in an IRB session with Ruby 3.4.2:

require 'socket'
Socket.tcp("foo.bar", 80)

Observe the error output:

/opt/rubies/3.4.2/lib/ruby/3.4.0/socket.rb:955:in 'Addrinfo.getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (Socket::ResolutionError)
  from /opt/rubies/3.4.2/lib/ruby/3.4.0/socket.rb:955:in 'Socket.resolve_hostname'
  from /opt/rubies/3.4.2/lib/ruby/3.4.0/socket.rb:711:in 'block (2 levels) in Socket.tcp_with_fast_fallback'

Expected Behavior:

The error backtrace should include the original application code that triggered the socket call, providing better context for debugging.

/Users/samuel/.rubies/ruby-3.1.6/lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)                          
  from /Users/samuel/.rubies/ruby-3.1.6/lib/ruby/3.1.0/socket.rb:227:in `foreach'
  from /Users/samuel/.rubies/ruby-3.1.6/lib/ruby/3.1.0/socket.rb:632:in `tcp'
  from (irb):2:in `<main>'               
  from /Users/samuel/.rubies/ruby-3.1.6/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
  from /Users/samuel/.rubies/ruby-3.1.6/bin/irb:25:in `load'
  from /Users/samuel/.rubies/ruby-3.1.6/bin/irb:25:in `<main>'

The change in how error backtraces are reported in Ruby 3.4 diminishes the ability to trace errors to user-level code, impacting debugging efforts. Can we restore or improve the backtrace reporting for socket-related errors.

Actions #1

Updated by ioquatix (Samuel Williams) 23 days ago

  • Description updated (diff)

Updated by byroot (Jean Boussier) 22 days ago

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED
Actions #3

Updated by byroot (Jean Boussier) 22 days ago

  • Status changed from Open to Closed

Applied in changeset git|580aa60051773e3512121088eb8ebaee8ce605ea.


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.

Updated by ioquatix (Samuel Williams) 20 days ago

Thanks @byroot (Jean Boussier), this must be some kind of record from bug report to merged fix.

Updated by k0kubun (Takashi Kokubun) 10 days ago

  • Backport changed from 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONE

ruby_3_4 e3fc29a9b7.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0