summaryrefslogtreecommitdiff
path: root/ext/socket/raddrinfo.c
AgeCommit message (Collapse)Author
2024-01-24Initialize errno variables and fix maybe-uninitialized warningsNobuyoshi Nakada
2024-01-22Make sure the correct error is raised for EAI_SYSTEM resolver failKJ Tsanaktsidis
In case of EAI_SYSTEM, getaddrinfo is supposed to set more detail in errno; however, because we call getaddrinfo on a thread now, and errno is threadlocal, that information is being lost. Instead, we just raise whatever errno happens to be on the calling thread (which can be something very confusing, like `ECHILD`). Fix it by explicitly propagating errno back to the calling thread through the getaddrinfo_arg structure. [Bug #20198]
2024-01-11Remove setaffinity of pthread for getaddrinfoYusuke Endoh
It looks like `sched_getcpu(3)` returns a strange number on some (virtual?) environments. I decided to remove the setaffinity mechanism because the performance does not appear to degrade on a quick benchmark even if removed. [Bug #20172]
2024-01-05Free pthread_attr after setting up the threadAdam Hess
[bug #20149]
2023-12-18[DOC] Correct the location of Addrinfo documentNobuyoshi Nakada
The document must be placed immediately before the class definition. No other statements can be placed in between.
2023-11-30Rename rsock_raise_socket_error to rsock_raise_resolution_errorMisaki Shioi
Again, rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
2023-11-28Retry pthread_create a few timesYusuke Endoh
According to https://bugs.openjdk.org/browse/JDK-8268605, pthread_create may fail spuriously. This change implements a simple retry as a modest measure, which is also used by JDK.
2023-11-07Prevent cpu_set_t overflow even if there are more than 63 coresYusuke Endoh
Do not use `pthread_attr_setaffinity_np` if `sched_getcpu()` exceeds `CPU_SETSIZE`. (Using `CPU_ALLOC()` would be more appropriate.)
2023-11-07Fix a memory leakYusuke Endoh
pointed by @nobu
2023-11-07Use pthread_attr_setaffinity_np instead of pthread_setaffinity_npYusuke Endoh
2023-11-07Detach a pthread after pthread_setaffinity_npYusuke Endoh
After a pthread for getaddrinfo is detached, we cannot predict when the thread will exit. It would lead to a segfault by setting pthread_setaffinity to the terminated pthread. I guess this problem would be more likely to occur in high-load environments. This change detaches the pthread after pthread_setaffinity is called. [Feature #19965]
2023-11-07Revert "Do not use pthread_setaffinity_np on s390x"Yusuke Endoh
This reverts commit de82439215dd2770ef9a3a2cf5798bdadb788533.
2023-10-25Do not use pthread_setaffinity_np on s390xYusuke Endoh
Looks like it randomly causes a segfault https://rubyci.s3.amazonaws.com/rhel_zlinux/ruby-master/log/20231025T093302Z.fail.html.gz ``` [11186/26148] TestNetHTTP_v1_2#test_set_form/home/chkbuild/build/20231025T093302Z/ruby/tool/lib/webrick/httprequest.rb:197: [BUG] Segmentation fault at 0x000003ff1ffff000 ruby 3.3.0dev (2023-10-25T07:50:00Z master 526292d9fe) [s390x-linux] ```
2023-10-24rb_getaddrinfo should return EAI_AGAIN instead of EAGAINYusuke Endoh
2023-10-24Indent critical regions with blocksYusuke Endoh
Cosmetic change per ko1's preference
2023-10-24Do not use pthread on mingwYusuke Endoh
2023-10-24Make rb_getnameinfo interruptibleYusuke Endoh
Same as previous commit for rb_getnameinfo.
2023-10-24Make rb_getaddrinfo interruptibleYusuke Endoh
When pthread_create is available, rb_getaddrinfo creates a pthread and executes getaddrinfo(3) in it. The caller thread waits for the pthread to complete, but detaches it if interrupted. This allows name resolution to be interuppted by Timeout.timeout, etc. even if it takes a long time (for example, when the DNS server does not respond). [Feature #19965]
2023-10-24Expand macro branches to make them plainYusuke Endoh
2023-10-24Refactor GETADDRINFO_IMPL instead of GETADDRINFO_EMUYusuke Endoh
This is a preparation for introducing cancellable getaddrinfo/getnameinfo.
2023-10-24refactor a call to getaddrinfoYusuke Endoh
2023-10-17Use rb_getnameinfo instead of directly using getnameinfoYusuke Endoh
2022-11-17Add support for `sockaddr_un` on Windows. (#6513)Samuel Williams
* Windows: Fix warning about undefined if_indextoname() * Windows: Fix UNIXSocket on MINGW and make .pair more reliable * Windows: Use nonblock=true for read tests with scheduler * Windows: Move socket detection from File.socket? to File.stat Add S_IFSOCK to Windows and interpret reparse points accordingly. Enable tests that work now. * Windows: Use wide-char functions to UNIXSocket This fixes behaviour with non-ASCII characters. It also fixes deletion of temporary UNIXSocket.pair files. * Windows: Add UNIXSocket tests for specifics of Windows impl. * Windows: fix VC build due to missing _snwprintf Avoid usage of _snwprintf, since it fails linking ruby.dll like so: linking shared-library x64-vcruntime140-ruby320.dll x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l whereas linking miniruby.exe succeeds. This patch uses snprintf on the UTF-8 string instead. Also remove branch GetWindowsDirectoryW, since it doesn't work. * Windows: Fix dangling symlink test failures Co-authored-by: Lars Kanis <kanis@comcard.de> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-11-09Use `rb_sprintf` instead of deprecated `sprintf`Nobuyoshi Nakada
2022-09-20[DOC] socket: fix wrong sample addresses (#6372)Sutou Kouhei
IPv6 link local address is fe80::/10 not ff80::/10: https://www.rfc-editor.org/rfc/rfc4291.html Link-Local unicast 1111111010 FE80::/10 2.5.6 IPv6 (deprecated) site local address is fec0::/10 not ffc0::/10: https://www.rfc-editor.org/rfc/rfc3513.html Site-local unicast 1111111011 FEC0::/10 2.5.6 Notes: Merged-By: kou <kou@clear-code.com>
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-03-17Fix broken links of rdocKazuhiro NISHIYAMA
- `www.ruby-lang.org` links to `./www.ruby-lang.org` - `cgi['field_name']` links to `./'field_name'`
2021-06-14Add scheduler hook `Addrinfo.getaddrinfo`. (#4375)Samuel Williams
Co-authored-by: Bruno Sutic <code@brunosutic.com> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2020-12-22Removed rb_cData entityNobuyoshi Nakada
* Use the wrapper of rb_cObject instead of data access * Replaced rest of extentions * Updated the version guard for Data * Added the version guard of rb_cData Notes: Merged: https://github.com/ruby/ruby/pull/3961
2020-12-07Revert getaddrinfo_a()Masaki Matsushita
getaddrinfo_a() gets stuck after fork(). To avoid this, we need 1 second sleep to wait for internal worker threads of getaddrinfo_a() to be finished, but that is unacceptable. [Bug #17220] [Feature #17134] [Feature #17187]
2020-12-06Call cleanup function for getaddrinfo_a(3) only before fork()Masaki Matsushita
Previously, rb_getaddrinfo_a_before_exec() is called from before_exec(). However, the function needs to be called only before fork(). The change moves it to before_fork().
2020-12-06Extend sleep time to 1.5 second in rb_getaddrinfo_a_before_exec()Masaki Matsushita
After 94d49ed31c, TestSocket#test_getaddrinfo_after_fork fails in some platforms. To avoid this, the change extends sleep time to 1.5 second.
2020-12-04Add a hook before fork() for getaddrinfo_a()Masaki Matsushita
We need stop worker threads in getaddrinfo_a() before fork(). This change adds a hook before fork() that cancel all outstanding requests and wait for all ongoing requests. Then, it waits for all worker threads to be finished. Fixes [Bug #17220]
2020-09-25Add resolve_timeout to TCPSocket [Feature #17134]Masaki Matsushita
2020-08-27Adjust indents [ci skip]Nobuyoshi Nakada
2020-08-27Make Socket.getaddrinfo interruptible (#2827)Kir Shatrov
Before, Socket.getaddrinfo was using a blocking getaddrinfo(3) call. That didn't allow to wrap it into Timeout.timeout or interrupt the thread in any way. Combined with the default 10 sec resolv timeout on many Unix systems, this can have a very noticeable effect on production Ruby apps being not resilient to DNS outages and timing out name resolution, and being unable to fail fast even with Timeout.timeout. Since we already have support for getaddrinfo_a(3), the async version of getaddrinfo, we should be able to make Socket.getaddrinfo leverage that when getaddrinfo_a version is available in the system (hence #ifdef HAVE_GETADDRINFO_A). Related tickets: https://bugs.ruby-lang.org/issues/16476 https://bugs.ruby-lang.org/issues/16381 https://bugs.ruby-lang.org/issues/14997 Notes: Merged-By: mmasaki <glass.saga@gmail.com>
2020-04-27Fix a typo [ci skip]Kazuhiro NISHIYAMA
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-09-10Support timeout for AddrinfoMasaki Matsushita
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as a keyword argument. If getaddrinfo_a(3) is available, the timeout will be applied for name resolution. Otherwise, it will be ignored. Socket.tcp accepts :resolv_timeout to use this feature. This commit is retry of 6382f5cc91ac9e36776bc854632d9a1237250da7. Test was failed on Solaris machines which don't have "http" in /etc/services. In this commit, use "ssh" instead.
2019-09-09Revert "Support timeout for Addrinfo"Masaki Matsushita
This reverts commit 6382f5cc91ac9e36776bc854632d9a1237250da7. test failed on Solaris.
2019-09-09Support timeout for AddrinfoMasaki Matsushita
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as a keyword argument. If getaddrinfo_a(3) is available, the timeout will be applied for name resolution. Otherwise, it will be ignored. Socket.tcp accepts :resolv_timeout to use this feature.
2019-08-27rb_ensure now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
2019-08-16Hoisted out unixsocket_len, triming NUL chars from sun_pathNobuyoshi Nakada
2019-07-16Constified afamily functionsNobuyoshi Nakada
2018-12-31Fix indents [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24UNREACHABLE_RETURNnobu
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-15raddrinfo.c: fix parse_numeric_portnobu
* ext/socket/raddrinfo.c (parse_numeric_port): necessary regardless of GETADDRINFO_EMU. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-09ext/socket/raddrinfo.c (addrinfo_mark): avoid needless branchnormal
gc.c (gc_mark_children, case T_DATA) does not use the dmark function pointer if DATA_PTR is NULL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-13Use PRIuSIZE format specifier for size_t valuesrhe
Use PRIuSIZE instead of PRIdSIZE. This fixes the exception message shown on too large xmalloc2. This commit also fixes other incorrect use of PRIdSIZE in other functions; though most of them are debug print. * gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow, gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed value is size_t, not ssize_t. * iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto. * sprintf.c (rb_str_format): Ditto. * thread_win32.c (native_thread_create): Ditto. * vm.c (get_param): Ditto. * ext/objspace/objspace_dump.c (dump_append_string_content, dump_object): Ditto. * ext/socket/raddrinfo.c (host_str, port_str): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e