summaryrefslogtreecommitdiff
path: root/ext/socket
AgeCommit message (Collapse)Author
2024-05-29Initialize errno variables and fix maybe-uninitialized warningsNobuyoshi Nakada
2024-03-14[Bug #20208] Revert "Set AI_ADDRCONFIG when making getaddrinfo(3) calls for ↵KJ Tsanaktsidis
outgoi… (#9791) Revert "Set AI_ADDRCONFIG when making getaddrinfo(3) calls for outgoing conns" This reverts commit 673ed41c81cf5a6951bcb2c3dec82d7bd6ea7440.
2024-03-14merge revision(s) 6c0e58a54e3fda604386d9c409e2a9998bbc9352: [Backport ↵NARUSE, Yui
#20198] (#10252) Make sure the correct error is raised for EAI_SYSTEM resolver fail 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] --- ext/socket/raddrinfo.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
2024-02-03merge revision(s) 1bd98c820da46a05328d2d53b8f748f28e7ee8f7: [Backport ↵NARUSE, Yui
#20172] (#9798) Remove setaffinity of pthread for getaddrinfo 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] --- ext/socket/extconf.rb | 2 -- ext/socket/raddrinfo.c | 48 ++++-------------------------------------------- 2 files changed, 4 insertions(+), 46 deletions(-)
2024-02-01merge revision(s) 6aacbd690ccde53f9b97c6673482cb11df3f2955: [Backport #20149]NARUSE, Yui
Free pthread_attr after setting up the thread [bug #20149] --- ext/socket/raddrinfo.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
2023-12-18Update `BasicSocket#recv` documentation on return valueJean Boussier
Ref: https://github.com/ruby/ruby/pull/6407 [Bug #19012] `0` is now interpreted as closed connection an not an empty packet, as these are very rare and pretty much useless.
2023-12-18[DOC] Add Socket::ResolutionError documentationNobuyoshi Nakada
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-12-18[DOC] Stop unintentional references to builtin or standard namesNobuyoshi Nakada
2023-12-17Revert "[DOC] Make undocumented socket constans nodoc"Nobuyoshi Nakada
This reverts commit cbda94edd80b0f664eda927f9ce9405b2074633a, because `:nodoc:` does not work for constants. In the case of `rb_define_const`, RDoc parses the preceeding comment as in `"/* definition: comment */"` form.
2023-12-17[DOC] Make undocumented socket constans nodocNobuyoshi Nakada
2023-12-17[DOC] Utilize COMMENTS.default_proc to add fallback documentsNobuyoshi Nakada
2023-12-12Partially revert "Set AI_ADDRCONFIG when making getaddrinfo(3) calls"KJ Tsanaktsidis
This _partially_ reverts commit d2ba8ea54a4089959afdeecdd963e3c4ff391748, but for UDP sockets only. With TCP sockets (and other things which use `rsock_init_inetsock`), the order of operations is to call `getaddrinfo(3)` with AF_UNSPEC, look at the returned addresses, pick one, and then call `socket(2)` with the family for that address (i.e. AF_INET or AF_INET6). With UDP sockets, however, this is reversed; `UDPSocket.new` takes an address family as an argument, and then calls `socket(2)` with that family. A subsequent call to UDPSocket#connect will then call `getaddrinfo(3)` with that family. The problem here is that... * If you are in a networking situation that _only_ has loopback addrs, * And you want to look up a name like "localhost" (or NULL) * And you pass AF_INET or AF_INET6 as the ai_family argument to getaddrinfo(3), * And you pass AI_ADDRCONFIG to the hints argument as well, then glibc on Linux will not return an address. This is because AI_ADDRCONFIG is supposed to return addresses for families we actually have an address for and could conceivably connect to, but also is documented to explicitly ignore localhost in that situation. It honestly doesn't make a ton of sense to pass AI_ADDRCONFIG if you're explicitly passing the address family anyway, because you're not looking for "an address for this name we can connect to"; you're looking for "an IPv(4|6) address for this name". And the original glibc bug that d2ba8ea5 was supposed to work around was related to parallel issuance of A and AAAA queries, which of course won't happen if an address family is explicitly specified. So, we fix this by not passing AI_ADDRCONFIG for calls to `rsock_addrinfo` that we also pass an explicit family to (i.e. for UDPsocket). [Bug #20048]
2023-12-10Change the semantics of rb_postponed_job_registerKJ Tsanaktsidis
Our current implementation of rb_postponed_job_register suffers from some safety issues that can lead to interpreter crashes (see bug #1991). Essentially, the issue is that jobs can be called with the wrong arguments. We made two attempts to fix this whilst keeping the promised semantics, but: * The first one involved masking/unmasking when flushing jobs, which was believed to be too expensive * The second one involved a lock-free, multi-producer, single-consumer ringbuffer, which was too complex The critical insight behind this third solution is that essentially the only user of these APIs are a) internal, or b) profiling gems. For a), none of the usages actually require variable data; they will work just fine with the preregistration interface. For b), generally profiling gems only call a single callback with a single piece of data (which is actually usually just zero) for the life of the program. The ringbuffer is complex because it needs to support multi-word inserts of job & data (which can't be atomic); but nobody actually even needs that functionality, really. So, this comit: * Introduces a pre-registration API for jobs, with a GVL-requiring rb_postponed_job_prereigster, which returns a handle which can be used with an async-signal-safe rb_postponed_job_trigger. * Deprecates rb_postponed_job_register (and re-implements it on top of the preregister function for compatability) * Moves all the internal usages of postponed job register pre-registration
2023-12-07Set AI_ADDRCONFIG when making getaddrinfo(3) calls for outgoing conns (#7295)KJ Tsanaktsidis
When making an outgoing TCP or UDP connection, set AI_ADDRCONFIG in the hints we send to getaddrinfo(3) (if supported). This will prompt the resolver to _NOT_ issue A or AAAA queries if the system does not actually have an IPv4 or IPv6 address (respectively). This makes outgoing connections marginally more efficient on non-dual-stack systems, since we don't have to try connecting to an address which can't possibly work. More importantly, however, this works around a race condition present in some older versions of glibc on aarch64 where it could accidently send the two outgoing DNS queries with the same DNS txnid, and get confused when receiving the responses. This manifests as outgoing connections sometimes taking 5 seconds (the DNS timeout before retry) to be made. Fixes #19144
2023-11-30Adjust indent [ci skip]Nobuyoshi Nakada
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-30Replace SocketError with Socket::ResolutionError in rsock_raise_socket_errorMisaki Shioi
rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
2023-11-30Add Socket::ResolutionError & Socket::ResolutionError#error_codeMisaki Shioi
Socket::ResolutionError#error_code returns Socket::EAI_XXX
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
2023-08-30BasicSocket#recv* return `nil` rather than an empty packetJean Boussier
[Bug #19012] man recvmsg(2) states: > Return Value > These calls return the number of bytes received, or -1 if an error occurred. > The return value will be 0 when the peer has performed an orderly shutdown. Not too sure how one is supposed to make the difference between a packet of size 0 and a closed connection. Notes: Merged: https://github.com/ruby/ruby/pull/6407
2023-06-30Don't check for null pointer in calls to freePeter Zhu
According to the C99 specification section 7.20.3.2 paragraph 2: > If ptr is a null pointer, no action occurs. So we do not need to check that the pointer is a null pointer. Notes: Merged: https://github.com/ruby/ruby/pull/8004
2023-06-12[Feature #19719] Universal Parseryui-knk
Introduce Universal Parser mode for the parser. This commit includes these changes: * Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions are passed via `struct rb_parser_config_struct` when this macro is enabled. * Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu. Notes: Merged: https://github.com/ruby/ruby/pull/7927
2023-04-06Update VPATH for socket, & dependenciesMatt Valentine-House
The socket extensions rubysocket.h pulls in the "private" include/gc.h, which now depends on vm_core.h. vm_core.h pulls in id.h when tool/update-deps generates the dependencies for the makefiles, it generates the line for id.h to be based on VPATH, which is configured in the extconf.rb for each of the extensions. By default VPATH does not include the actual source directory of the current Ruby so the dependency fails to resolve and linking fails. We need to append the topdir and top_srcdir to VPATH to have the dependancy picked up correctly (and I believe we need both of these to cope with in-tree and out-of-tree builds). I copied this from the approach taken in https://github.com/ruby/ruby/blob/master/ext/objspace/extconf.rb#L3 Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-02-28Update the depend filesMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/7310
2023-02-27Remove intern/gc.h from Make depsMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/7330
2023-02-08Extract include/ruby/internal/attr/packed_struct.hNobuyoshi Nakada
Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the macros bellow: * `RBIMPL_ATTR_PACKED_STRUCT_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_END` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END` Notes: Merged: https://github.com/ruby/ruby/pull/7268
2023-01-30Extract check for RSTRING_SOCKLENNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7195
2023-01-16fix typo in comments / autodocRick Hull
replace _socktype_ with _type_ in the comments Notes: Merged: https://github.com/ruby/ruby/pull/7127
2022-12-15Remove `require 'io/wait'` where it's no longer necessary. (#6932)Samuel Williams
* Remove `require 'io/wait'` as it's part of core now. * Update ruby specs using version gates. * Add note about why it's conditional. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-12-15socket.rb - simplify check for the methodNobuyoshi Nakada
2022-12-14socket.rb - don't load io/wait (#6922)MSP-Greg
See d2166c09b08fc1 and #6036 for more context. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-11-30Removed documentation for incomplete option about [Feature #17134]Hiroshi SHIBATA
2022-11-21Use class methods of `File` over `Kernel.open` and `IO.read`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/6777
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>