Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the error codes as Socket::EAI_XXX when getaddrinfo and getnameinfo fail #9018

Merged
merged 5 commits into from
Nov 30, 2023

Conversation

shioimm
Copy link
Contributor

@shioimm shioimm commented Nov 23, 2023

This PR allows getting the error codes as Socket::EAI_XXX when getaddrinfo and getnameinfo fail.

The purpose of this PR

This PR is necessary to implement Happy Eyeballs version 2 (RFC 8305) in Socket.tcp.
In HEv2, EAI_ADDRFAMILY and EAI_AGAIN obtained during name resolution should be ignored. However, there is currently no way to ask SocketError for errors returned by getaddrinfo, so I opened this PR.

Changes

  • Added Socket::ResolutionError as a subclass of SocketError
  • Added an attribute of Socket::ResolutionError to get error code via `#error_code
  • Replaced SocketError (rb_eSocket) with Socket::ResolutionError (rb_eResolutionError) in rsock_raise_socket_error because this function is only called when getaddrinfo and getnameinfo fail
  • Renamed rsock_raise_socket_error to rock_raise_resolution_error for the same reason

Note

Socket::ResolutionError is a subclass of SocketError, so it does not affect rescue SocketError in source codes.

@mame mame requested a review from akr November 23, 2023 10:56
shioimm added a commit to shioimm/net-ftp that referenced this pull request Nov 23, 2023
The following PR changes cause Socket::ResolutionError, a subclass of SocketError, to be raised in this test case.
ruby/ruby#9018

While `assert_raise` verifies that the error being raised is indeed a SocketError, `assert_raises` can verify that it is a SocketError or a subclass thereof. It will avoid unwanted test failures.
Socket::ResolutionError#error_code returns Socket::EAI_XXX
…t_error

rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
Again, rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
shioimm added a commit to shioimm/net-ftp that referenced this pull request Nov 29, 2023
The following PR changes cause Socket::ResolutionError, a subclass of SocketError, to be raised in this test case.
ruby/ruby#9018
In this repository, make it fall back to SocketError if it is not defined.
@mame mame merged commit 5baa2b9 into ruby:master Nov 30, 2023
99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants