Граф коммитов

283 Коммитов

Автор SHA1 Сообщение Дата
Masaki Matsushita 5d8bcc4870 Revert getaddrinfo_a()
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-07 13:33:53 +09:00
Masaki Matsushita 5e58a9033f Reduce timeout of test_getaddrinfo_after_fork 2020-12-05 17:43:35 +09:00
Benoit Daloze b4ec4a41c2 Guard all accesses to RubyVM::MJIT with defined?(RubyVM::MJIT) &&
* Otherwise those tests, etc cannot run on alternative Ruby implementations.
2020-12-04 16:45:54 +01:00
Masaki Matsushita 94d49ed31c Add a hook before fork() for getaddrinfo_a()
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-12-04 23:31:51 +09:00
Masaki Matsushita 511fe23fa2 Add resolve_timeout to TCPSocket [Feature #17134] 2020-09-25 15:19:14 +09:00
Jeremy Evans ed27c2514c Update UnixSocket#recv_io tests to handle receiving a UnixSocket
Receiving UnixSocket works fine if you don't provide a mode, and
I think it is reasonable to expect that you should not provide
a mode if klass.for_fd would not accept a mode.

Fixes [Bug #11778]
2020-09-22 15:44:34 -07:00
Kir Shatrov 2038cc6cab
Make Socket.getaddrinfo interruptible (#2827)
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
2020-08-27 16:39:13 +09:00
Yusuke Endoh 3d71388710 test/socket/test_addrinfo.rb: Fix syntax error
Sorry!
2020-06-04 11:29:39 +09:00
Yusuke Endoh 980655ce83 test/socket/test_addrinfo.rb: Suppress Errno::EACCES when addr is in use
MinGW seems to raise Errno::EACCES instead of EADDRINUSE when bind fails
due to in use.

https://github.com/ruby/ruby/runs/736825846
```
  2) Error:
TestSocketAddrinfo#test_connect_from:
Errno::EACCES: Permission denied - bind(2) for 0.0.0.0:49721
    D:/a/ruby/ruby/build/.ext/common/socket.rb:54:in `bind'
    D:/a/ruby/ruby/build/.ext/common/socket.rb:54:in `connect_internal'
    D:/a/ruby/ruby/build/.ext/common/socket.rb:114:in `connect_from'
    D:/a/ruby/ruby/src/test/socket/test_addrinfo.rb:379:in `block in test_connect_from'
    D:/a/ruby/ruby/src/test/socket/test_addrinfo.rb:374:in `open'
    D:/a/ruby/ruby/src/test/socket/test_addrinfo.rb:374:in `test_connect_from'
```
2020-06-04 11:24:19 +09:00
Samuel Williams 0e3b0fcdba
Thread scheduler for light weight concurrency. 2020-05-14 22:10:55 +12:00
Nobuyoshi Nakada 7397b9f786
Fixed leaked fds 2020-05-06 12:45:01 +09:00
Kazuhiro NISHIYAMA 2f6a8baac6
Test interfaces include localhost
When interfaces do not include localhost,
some other tests may fail.
2019-12-06 16:03:16 +09:00
Masaki Matsushita f5024de002 Remove check of ai.protocol
Solaris 10 returns addrinfo.ai_protocol as 0, not 6.
2019-09-10 12:39:49 +09:00
Masaki Matsushita 0e9d56f5e7 Support timeout for Addrinfo
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 6382f5cc91.
Test was failed on Solaris machines which don't have "http" in
/etc/services. In this commit, use "ssh" instead.
2019-09-10 10:10:59 +09:00
Masaki Matsushita c4efbf663e Revert "Support timeout for Addrinfo"
This reverts commit 6382f5cc91.
test failed on Solaris.
2019-09-09 20:34:51 +09:00
Masaki Matsushita 8c09de38c5 Fix expected ip_port 2019-09-09 18:44:42 +09:00
Masaki Matsushita 0fb2457d79 Fix service name for test
change service name to fix failed test on Solaris
2019-09-09 18:35:19 +09:00
Masaki Matsushita 461663f52a Fix domain name for test 2019-09-09 15:05:38 +09:00
Masaki Matsushita 6382f5cc91 Support timeout for Addrinfo
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-09-09 14:34:05 +09:00
Takashi Kokubun afe8bf2489
Try extending timeout of IO.select
hoping to stabilize:
https://app.wercker.com/ruby/ruby/runs/mjit-test1/5d6df8a8a952c20008acf75b?step=5d6df90e4971a6000714c627
2019-09-03 20:34:52 +09:00
Kazuhiro NISHIYAMA 63ab7046a1
Skip POINTOPOINT of IPv4 too instead of IPv6 only
Fix following error on `utun*`:
```
  1) Error:
TestSocket#test_udp_server:
Errno::ECONNREFUSED: Connection refused - recvmsg(2)
```
2019-09-02 12:01:47 +09:00
Nobuyoshi Nakada 409b0ec4c3
Suppress unused variable warnings 2019-06-30 11:45:37 +09:00
Nobuyoshi Nakada 45ba027d08
Removed unused variables 2019-06-30 08:45:01 +09:00
normal 9d74d402e1 disable non-blocking pipes and sockets by default
There seems to be a compatibility problems with Rails +
Rack::Deflater; so we revert this incompatibility.

This effectively reverts r65922; but keeps the bugfixes to
better support non-blocking sockets and pipes for future use.

[Bug #15356] [Bug #14968]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 20:00:00 +00:00
normal 6a65f2b1e4 io + socket: make pipes and sockets nonblocking by default
All normal Ruby IO methods (IO#read, IO#gets, IO#write, ...) are
all capable of appearing to be "blocking" when presented with a
file description with the O_NONBLOCK flag set; so there is
little risk of incompatibility within Ruby-using programs.

The biggest compatibility risk is when spawning external
programs.  As a result, stdin, stdout, and stderr are now always
made blocking before exec-family calls.

This change will make an event-oriented MJIT usable if it is
waiting on pipes on POSIX_like platforms.

It is ALSO necessary to take advantage of (proposed lightweight
concurrency (aka "auto-Fiber") or any similar proposal for
network concurrency: https://bugs.ruby-lang.org/issues/13618

Named-pipe (FIFO) are NOT yet non-blocking by default since
they are rarely-used and may introduce compatibility problems
and extra syscall overhead for a common path.

Please revert this commit if there are problems and if I am afk
since I am afk a lot, lately.

[ruby-core:89950] [Bug #14968]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22 08:46:51 +00:00
normal 54ad3167e8 tests: support Linux kernels with CONFIG_IPV6=n
Detecting the presence of constants in C headers is insufficient,
as a Linux kernel can be built with CONFIG_IPV6=n

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 05:18:49 +00:00
normal ce48b55805 test/socket/test_socket.rb (timestamp_retry_rw): IO.select before recvmsg
CI failures are still happening from these tests, but try
to break out of it earlier instead of holding up the job.

[Bug #14898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-20 20:45:40 +00:00
normal 12f11714c2 test/socket/test_socket.rb (test_timestampns): retry send
It looks like we need to retry test_timestampns in addition
to test_timestamp; so share some code while we're at it.

cf. http://ci.rvm.jp/results/trunk-test@frontier/1153126
[ruby-core:88104] [Bug #14898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-02 06:09:38 +00:00
normal eb78bedab7 test/socket/test_socket.rb (test_timestamp): retry send
I theorize there can be UDP packet loss even over loopback if
the kernel is under memory pressure.  Retry sending periodically
until recvmsg succeeds.

i[ruby-core:87842] [Bug #14898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-07 05:34:03 +00:00
nobu 8794dec6a5 unixsocket.c: check NUL bytes
* ext/socket/unixsocket.c (rsock_init_unixsock): check NUL bytes.
  https://hackerone.com/reports/302997

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 10:08:57 +00:00
nobu a41005eb6a init.c: encode socket error message
* ext/socket/init.c (rsock_raise_socket_error): on Windows, encode
  error messages from wide characters to the default encodings.
  [ruby-core:84972] [Bug #14384]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-23 15:31:22 +00:00
eregon 15689ed778 Fix test-all tests to avoid creating report_on_exception warnings
* The warnings are shown by Thread.report_on_exception defaulting to
  true. [Feature #14143] [ruby-core:83979]
* Improves tests by narrowing down the scope where an exception
  is expected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 18:44:49 +00:00
normal ba5eb6458a socket: fix BasicSocket#*_nonblock buffering bugs from r58400
IO#read_nonblock and IO#write_nonblock take into account
buffered data, so the Linux-only BasicSocket#read_nonblock
and BasicSocket#write_nonblock methods must, too.

This bug was only introduced in r58400
("socket: avoid fcntl for read/write_nonblock on Linux")
and does not affect any stable release.

* ext/socket/basicsocket.c (rsock_init_basicsocket):
* ext/socket/init.c (rsock_s_recvfrom_nonblock):
* ext/socket/init.c (rsock_init_socket_init):
* ext/socket/lib/socket.rb (def read_nonblock):
* ext/socket/lib/socket.rb (def write_nonblock):
* ext/socket/rubysocket.h (static inline void rsock_maybe_wait_fd):
* test/socket/test_basicsocket.rb (def test_read_write_nonblock):
  [Feature #13362]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 23:26:48 +00:00
nobu fb89004a3b socket.c: null byte at Socket.getnameinfo
* ext/socket/socket.c (sock_s_getnameinfo): check null byte.
  patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
  [Bug #13994]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-11 06:16:04 +00:00
kazu 6064132c42 Remove unnecessary `require 'thread'`
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-08 07:00:01 +00:00
normal fba0b81e18 test/socket/test_basicsocket.rb (socks): bind explicitly to localhost
Binding to a potentially public IP in a test can cause problems
if hit by a random port scanner or something...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-15 07:33:10 +00:00
normal e79ecc540f test/socket/test_basicsocket: handle :wait_readable on read_nonblock
On some systems with slower local sockets, :wait_readable may
happen and we should wait on it to drain the socket.
This is a possible fix for https://bugs.ruby-lang.org/issues/13491

* test/socket/test_basicsocket.rb (test_read_write_nonblock):
  handle :wait_readable on read_nonblock

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-21 20:38:58 +00:00
normal c32fc82d0e socket: avoid fcntl for read/write_nonblock on Linux
On platforms where MSG_DONTWAIT works reliably on all sockets
(so far, I know of Linux), we can avoid fcntl syscalls and
implement IO#write_nonblock and IO#read_nonblock in terms of the
socket-specific send and recv family of syscalls.

This avoids side effects on the socket, and also encourages
generic code to be written in cases where IO wrappers like
OpenSSL::SSL::SSLSocket are used.

Perhaps in the future, side-effect-free non-blocking I/O can
be standard on all files and OSes: https://cr.yp.to/unix/nonblock.html

* ext/socket/lib/socket.rb (read_nonblock, write_nonblock):
  Linux-specific wrapper without side effects
  [ruby-core:80780] [Feature #13362]
* test/socket/test_basicsocket.rb (test_read_write_nonblock):
  new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-19 01:08:16 +00:00
nobu 8c84803d80 IPSocket#inspect
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-14 10:03:43 +00:00
nobu 4b298ad77a Use qualified names
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-30 06:22:30 +00:00
usa 3912e4fa3b * ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr
instead of (Safe)StringValue, to detect NUL byte in the string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 15:33:06 +00:00
usa 0e94f4a002 * test/socket/test_addrinfo.rb (TestSocketAddrinfo#test_addrinfo_ip): previous
test logic depended on platform specific implementation.  use more portable
  logic.  this fixes a test failure on Windows.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 12:51:14 +00:00
nobu 632097082b test_addrinfo.rb: signle digit address
* test/socket/test_addrinfo.rb (test_addrinfo_ip): use single
  digit address so that the values are same in both decimal and
  octal.  some platform zero-prefixed dotted-decimal is parsed as
  an octal value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 11:23:32 +00:00
nobu 94a91b1d60 raddrinfo.c: fix for SHARABLE_MIDDLE_SUBSTRING
* ext/socket/raddrinfo.c (host_str, port_str): use RSTRING_LEN
  instead of strlen, since RSTRING_PTR StringValueCStr may not be
  NUL-terminated when SHARABLE_MIDDLE_SUBSTRING=1.  reported by
  @tmtms, http://twitter.com/tmtms/status/736910516229005312

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 07:28:55 +00:00
nobu bfc9c3766f test_addrinfo.rb: special hostnames
* test/socket/test_addrinfo.rb (test_addrinfo_ip): add tests for
  special hostnames, <any> and <broadcast>.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-30 06:12:13 +00:00
odaira acfd12ae36 * test/socket/test_socket.rb (test_udp_recvmsg_truncation):
AIX does not set the MSG_TRUNC flag for a message partially read
  by recvmsg(2) with the MSG_PEEK flag set.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-10 00:55:37 +00:00
odaira bf5d2c74c9 * test/socket/test_addrinfo.rb (test_ipv6_address_predicates):
IN6_IS_ADDR_V4COMPAT and IN6_IS_ADDR_V4MAPPED are broken
  on AIX, so skip related tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-05 00:54:17 +00:00
odaira 1874524d42 Sat Mar 5 09:17:54 2016 Rei Odaira <Rei.Odaira@gmail.com>
* test/rinda/test_rinda.rb (test_make_socket_ipv4_multicast):
  The fifth argument to getsockopt(2) should be modified to
  indicate the actual size of the value on return,
  but not in AIX. This is a know bug. Skip related tests.
* test/rinda/test_rinda.rb (test_ring_server_ipv4_multicast):
  ditto.
* test/rinda/test_rinda.rb (test_make_socket_unicast): ditto.
* test/socket/test_basicsocket.rb (test_getsockopt): ditto.
* test/socket/test_sockopt.rb (test_bool): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-05 00:29:39 +00:00
nobu 0bc5341690 option.c: single byte boolean
* ext/socket/option.c (sockopt_bool): relax boolean size to be one
  too not only sizeof(int).  Winsock getsockopt() returns a single
  byte as a boolean socket option.  [ruby-core:72730] [Bug #11958]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-17 06:31:36 +00:00
naruse 6e181393c6 ignore exception is the address is IPv6
some environments disables IPv6 even if they have IPv6 addresses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-24 17:53:11 +00:00