Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Do not wait connection attempt delay without in progress fds #12087

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

Conversation

shioimm
Copy link
Contributor

@shioimm shioimm commented Nov 14, 2024

Reset Connection Attempt Delay when connection fails and there is no other socket connection in progress.
This is intended to resolve an issue that was temporarily worked around in Pull Request #12062.

TCPServer::new (used in tests such as TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write) can only connect over either IPv6 or IPv4, depending on the environment.
Since HEv2 attempts to connect over IPv6 first, environments where IPv6 connections are unavailable return ECONNREFUSED immediately.
In such cases, the client should immediately retry the connection over IPv4.
However, HEv2 includes a specification for a "Connection Attempt Delay," where it waits 250ms after the previous connection attempt before starting the next one.
This delay causes Net::OpenTimeout (100ms) to be exceeded while waiting for the next connection attempt to start.

With this change, when a connection attempt fails, if there are sockets still attempting to connect and there are addresses yet to be tried, the Connection Attempt Delay will be resetted, allowing the next connection attempt to start immediately.


Additionally, the following minor fixes have been made:

  • The nfds value used for select(2) is now reset with each wait.

Reset Connection Attempt Delay when connection fails and there is no other socket connection in progress.
This is intended to resolve an issue that was temporarily worked around in Pull Request ruby#12062.

`TCPServer::new` (used in tests such as `TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write`) can only connect over either IPv6 or IPv4, depending on the environment.
Since HEv2 attempts to connect over IPv6 first, environments where IPv6 connections are unavailable return ECONNREFUSED immediately.
In such cases, the client should immediately retry the connection over IPv4.
However, HEv2 includes a specification for a "Connection Attempt Delay," where it waits 250ms after the previous connection attempt before starting the next one.
This delay causes Net::OpenTimeout (100ms) to be exceeded while waiting for the next connection attempt to start.

With this change, when a connection attempt fails, if there are sockets still attempting to connect and there are addresses yet to be tried, the Connection Attempt Delay will be resetted, allowing the next connection attempt to start immediately.

---

Additionally, the following minor fixes have been made:

- The `nfds` value used for select(2) is now reset with each wait.
@shioimm shioimm force-pushed the do-not-wait-connection-attempt-delay-without-in-progress-fds branch from aa797a0 to b2f610b Compare November 14, 2024 13:50
@shioimm shioimm marked this pull request as ready for review November 14, 2024 15:24
@shioimm shioimm merged commit fd4b274 into ruby:master Nov 14, 2024
70 checks passed
shioimm added a commit to shioimm/ruby that referenced this pull request Nov 30, 2024
… connection failure.

This change addresses a case that was overlooked in ruby#12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.
shioimm added a commit to shioimm/ruby that referenced this pull request Nov 30, 2024
… connection failure

This change addresses a case that was overlooked in ruby#12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.
shioimm added a commit to shioimm/ruby that referenced this pull request Nov 30, 2024
… connection failure

This change addresses a case that was overlooked in ruby#12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.

Additionally, the following minor fixes have been made:
- Refactor: Remove unnecessary members
shioimm added a commit to shioimm/ruby that referenced this pull request Nov 30, 2024
… connection failure

This change addresses a case that was overlooked in ruby#12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.

Additionally, the following minor fixes have been made:
- Refactor: Remove unnecessary members
shioimm added a commit that referenced this pull request Nov 30, 2024
… connection failure (#12223)

* Improve the conditions for clearing the Connection Attempt Delay upon connection failure

This change addresses a case that was overlooked in #12087.
In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met:

- No other sockets were attempting a connection
- There were addresses still available to start a new connection

In this update, the second condition has been removed.
As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them.

If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before.

---

Additionally, the following minor fixes have been made:

* Refactor: Remove unnecessary members
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant