Skip to content

Commit 3d07754

Browse files
authored
Improve the conditions for clearing the Connection Attempt Delay upon connection failure (ruby#12223)
* Improve the conditions for clearing the Connection Attempt Delay upon 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
1 parent fdf60d7 commit 3d07754

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

ext/socket/ipsocket.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ struct fast_fallback_inetsock_arg
226226
int *families;
227227
int family_size;
228228
int additional_flags;
229-
rb_nativethread_lock_t *lock;
230229
struct fast_fallback_getaddrinfo_entry *getaddrinfo_entries[2];
231230
struct fast_fallback_getaddrinfo_shared *getaddrinfo_shared;
232231
int wait;
@@ -601,8 +600,6 @@ init_fast_fallback_inetsock_internal(VALUE v)
601600
rb_nativethread_lock_initialize(arg->getaddrinfo_shared->lock);
602601

603602
arg->getaddrinfo_shared->notify = hostname_resolution_notifier;
604-
arg->getaddrinfo_shared->connection_attempt_fds = arg->connection_attempt_fds;
605-
arg->getaddrinfo_shared->connection_attempt_fds_size = arg->connection_attempt_fds_size;
606603
arg->getaddrinfo_shared->cancelled = false;
607604
wait_arg.cancelled = &arg->getaddrinfo_shared->cancelled;
608605

@@ -620,7 +617,6 @@ init_fast_fallback_inetsock_internal(VALUE v)
620617
if (arg->family_size == 1) {
621618
arg->getaddrinfo_shared->node = NULL;
622619
arg->getaddrinfo_shared->service = NULL;
623-
arg->getaddrinfo_shared->refcount = 1;
624620

625621
int family = arg->families[0];
626622
arg->remote.res = rsock_addrinfo(
@@ -1007,9 +1003,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
10071003
if (connected_fd >= 0) break;
10081004

10091005
if (!in_progress_fds(arg->connection_attempt_fds_size)) {
1010-
if (any_addrinfos(&resolution_store)) {
1011-
connection_attempt_delay_expires_at = NULL;
1012-
} else if (resolution_store.is_all_finised) {
1006+
if (!any_addrinfos(&resolution_store) && resolution_store.is_all_finised) {
10131007
if (local_status < 0) {
10141008
host = arg->local.host;
10151009
serv = arg->local.serv;
@@ -1023,6 +1017,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
10231017
rsock_syserr_fail_host_port(last_error.ecode, syscall, host, serv);
10241018
}
10251019
}
1020+
connection_attempt_delay_expires_at = NULL;
10261021
user_specified_connect_timeout_at = NULL;
10271022
}
10281023
}

ext/socket/rubysocket.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,8 @@ struct fast_fallback_getaddrinfo_entry
440440

441441
struct fast_fallback_getaddrinfo_shared
442442
{
443-
int notify, refcount, connection_attempt_fds_size;
443+
int notify, refcount;
444444
int cancelled;
445-
int *connection_attempt_fds;
446445
char *node, *service;
447446
rb_nativethread_lock_t *lock;
448447
struct fast_fallback_getaddrinfo_entry getaddrinfo_entries[FLEX_ARY_LEN];

0 commit comments

Comments
 (0)