diff options
author | Misaki Shioi <[email protected]> | 2024-11-23 23:04:02 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-23 23:04:02 +0900 |
commit | 8d575e4972343986d4d2d987b0d51d90398a7f29 (patch) | |
tree | 0e92e122ac35797797af27bb9e6c9d3491d2fbea /ext/socket | |
parent | 34e36a72a7a01e720140fc48a31f3444b3b62c53 (diff) |
Save the error that occurred during name resolution (#12155)
even if a system call error happens after the name resolution failure in the child thread.
pipe and write(2) are used to notify the main thread of the name resolution results from the child thread.
After name resolution is completed in the child thread, if the call to write(2) fails, the main thread retrieves the resolved addresses.
However, when name resolution failed, the corresponding error was not being saved in `last_error`.
With this change, name resolution failures will now be saved in last_error even if the write(2) call in the child thread fails.
Notes
Notes:
Merged-By: shioimm <[email protected]>
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/ipsocket.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c index 9530dac482..86a4f2659b 100644 --- a/ext/socket/ipsocket.c +++ b/ext/socket/ipsocket.c @@ -1087,6 +1087,48 @@ init_fast_fallback_inetsock_internal(VALUE v) status = wait_arg.status = 0; } + if (!resolution_store.is_all_finised) { + if (!resolution_store.v6.finished && arg->getaddrinfo_entries[IPV6_ENTRY_POS]->has_syserr) { + resolution_store.v6.finished = true; + + if (arg->getaddrinfo_entries[IPV6_ENTRY_POS]->err) { + last_error.type = RESOLUTION_ERROR; + last_error.ecode = arg->getaddrinfo_entries[IPV6_ENTRY_POS]->err; + syscall = "getaddrinfo(3)"; + resolution_store.v6.has_error = true; + } else { + resolution_store.v6.ai = arg->getaddrinfo_entries[IPV6_ENTRY_POS]->ai; + } + + if (resolution_store.v4.finished) { + resolution_store.is_all_finised = true; + resolution_delay_expires_at = NULL; + user_specified_resolv_timeout_at = NULL; + } + } + if (!resolution_store.v4.finished && arg->getaddrinfo_entries[IPV4_ENTRY_POS]->has_syserr) { + resolution_store.v4.finished = true; + + if (arg->getaddrinfo_entries[IPV4_ENTRY_POS]->err) { + last_error.type = RESOLUTION_ERROR; + last_error.ecode = arg->getaddrinfo_entries[IPV4_ENTRY_POS]->err; + syscall = "getaddrinfo(3)"; + resolution_store.v4.has_error = true; + } else { + resolution_store.v4.ai = arg->getaddrinfo_entries[IPV4_ENTRY_POS]->ai; + } + + if (resolution_store.v6.finished) { + resolution_store.is_all_finised = true; + resolution_delay_expires_at = NULL; + user_specified_resolv_timeout_at = NULL; + } else { + set_timeout_tv(&resolution_delay_storage, 50, now); + resolution_delay_expires_at = &resolution_delay_storage; + } + } + } + if (!any_addrinfos(&resolution_store)) { if (!in_progress_fds(arg->connection_attempt_fds_size) && resolution_store.is_all_finised) { @@ -1113,34 +1155,6 @@ init_fast_fallback_inetsock_internal(VALUE v) rb_raise(etimedout_error, "user specified timeout"); } } - - if (!resolution_store.is_all_finised) { - if (!resolution_store.v6.finished && arg->getaddrinfo_entries[IPV6_ENTRY_POS]->has_syserr) { - resolution_store.v6.ai = arg->getaddrinfo_entries[IPV6_ENTRY_POS]->ai; - resolution_store.v6.finished = true; - - if (resolution_store.v4.finished) { - resolution_store.is_all_finised = true; - wait_arg.readfds = NULL; - resolution_delay_expires_at = NULL; - user_specified_resolv_timeout_at = NULL; - } - } - if (!resolution_store.v4.finished && arg->getaddrinfo_entries[IPV4_ENTRY_POS]->has_syserr) { - resolution_store.v4.ai = arg->getaddrinfo_entries[IPV4_ENTRY_POS]->ai; - resolution_store.v4.finished = true; - - if (resolution_store.v6.finished) { - resolution_store.is_all_finised = true; - wait_arg.readfds = NULL; - resolution_delay_expires_at = NULL; - user_specified_resolv_timeout_at = NULL; - } else { - set_timeout_tv(&resolution_delay_storage, 50, now); - resolution_delay_expires_at = &resolution_delay_storage; - } - } - } } rb_thread_check_ints(); |