<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/ext/socket, branch v3_4_1</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>Introduce a timeout to prevent `rb_thread_fd_select` from hanging with write(2) failure (#12457)</title>
<updated>2024-12-24T18:06:02+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-24T18:06:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=3be1baab82d8627ce52391030160bcbca69db01d'/>
<id>3be1baab82d8627ce52391030160bcbca69db01d</id>
<content type='text'>
Rarely, there are cases where a write(2) call from a child thread
to notify the main thread of the completion of name resolution fails.
If this happens while the main thread is waiting in `rb_thread_fd_select`,
rb_thread_fd_select may not notice that the name resolution has completed and end up hanging.

This issue becomes a problem when there are no sockets currently being connected,
no addresses ready for immediate connection attempts,
and name resolution has already completed for one address family
while the main thread is waiting for the name resolution of the other address family.
(If name resolution is not completed for either address family,
the chances of write(2) failing in both child threads are likely low.)

To avoid this issue, a timeout is introduced to rb_thread_fd_select under the above conditions.
This way, even if the issue occurs,
the completion of name resolution should still be detected
in the subsequent `if (!resolution_store.is_all_finished) ...` block.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Rarely, there are cases where a write(2) call from a child thread
to notify the main thread of the completion of name resolution fails.
If this happens while the main thread is waiting in `rb_thread_fd_select`,
rb_thread_fd_select may not notice that the name resolution has completed and end up hanging.

This issue becomes a problem when there are no sockets currently being connected,
no addresses ready for immediate connection attempts,
and name resolution has already completed for one address family
while the main thread is waiting for the name resolution of the other address family.
(If name resolution is not completed for either address family,
the chances of write(2) failing in both child threads are likely low.)

To avoid this issue, a timeout is introduced to rb_thread_fd_select under the above conditions.
This way, even if the issue occurs,
the completion of name resolution should still be detected
in the subsequent `if (!resolution_store.is_all_finished) ...` block.</pre>
</div>
</content>
</entry>
<entry>
<title>Improve doc for `Socket::ResolutionError` (#12434)</title>
<updated>2024-12-23T06:05:00+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-23T06:05:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=34e6bb48af2814eefd91968c58c1dede3b56f30e'/>
<id>34e6bb48af2814eefd91968c58c1dede3b56f30e</id>
<content type='text'>
Also, a topic about Socket::ResolutionError is added to NEWS</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Also, a topic about Socket::ResolutionError is added to NEWS</pre>
</div>
</content>
</entry>
<entry>
<title>Wrap `do_fast_fallback_getaddrinfo` with `rb_thread_prevent_fork` (#12366)</title>
<updated>2024-12-18T00:48:26+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-18T00:48:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=498d6eb114c52bd16a6821029959e88ed8f87396'/>
<id>498d6eb114c52bd16a6821029959e88ed8f87396</id>
<content type='text'>
Wrap `do_fast_fallback_getaddrinfo` with `rb_thread_prevent_fork`

Referencing PR #10864,
wrap `do_fast_fallback_getaddrinfo` with `rb_thread_prevent_fork`
to avoid fork safety issues.

`do_fast_fallback_getaddrinfo` internally uses getaddrinfo(3),
leading to fork safety issues, as described in PR #10864.
This change ensures that `do_fast_fallback_getaddrinfo`
is guarded by `rb_thread_prevent_fork`,
preventing fork during its execution and avoiding related issues.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Wrap `do_fast_fallback_getaddrinfo` with `rb_thread_prevent_fork`

Referencing PR #10864,
wrap `do_fast_fallback_getaddrinfo` with `rb_thread_prevent_fork`
to avoid fork safety issues.

`do_fast_fallback_getaddrinfo` internally uses getaddrinfo(3),
leading to fork safety issues, as described in PR #10864.
This change ensures that `do_fast_fallback_getaddrinfo`
is guarded by `rb_thread_prevent_fork`,
preventing fork during its execution and avoiding related issues.</pre>
</div>
</content>
</entry>
<entry>
<title>[DOC] Fix broken parameter display and see links for Socket</title>
<updated>2024-12-16T01:07:39+00:00</updated>
<author>
<name>nvh0412</name>
<email>nvh0412@gmail.com</email>
</author>
<published>2024-12-15T10:47:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9389a27e4967a170da98af8cd33d6ee1c063d3d5'/>
<id>9389a27e4967a170da98af8cd33d6ee1c063d3d5</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix broken links to `Socket.tcp_fast_fallback=`</title>
<updated>2024-12-15T06:36:08+00:00</updated>
<author>
<name>Stan Lo</name>
<email>stan.lo@shopify.com</email>
</author>
<published>2024-12-14T19:06:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e9926afb24d00ffd721c39d535a3b91cb8a0ea56'/>
<id>e9926afb24d00ffd721c39d535a3b91cb8a0ea56</id>
<content type='text'>
Since it's a singleton method, it should be referenced as `Socket.tcp_fast_fallback=`,
not `Socket#tcp_fast_fallback=`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since it's a singleton method, it should be referenced as `Socket.tcp_fast_fallback=`,
not `Socket#tcp_fast_fallback=`.
</pre>
</div>
</content>
</entry>
<entry>
<title>Improve APIs for Globally Enabling/Disabling fast_fallback in Socket (#12257)</title>
<updated>2024-12-14T06:51:19+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-14T06:51:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9f924e2f13992241c447190a9eb139bf46dcb8d9'/>
<id>9f924e2f13992241c447190a9eb139bf46dcb8d9</id>
<content type='text'>
This change includes the following updates:
- Added an environment variable `RUBY_TCP_NO_FAST_FALLBACK` to control enabling/disabling fast_fallback
- Updated documentation and man pages
- Revised the implementation of Socket.tcp_fast_fallback= and Socket.tcp_fast_fallback, which previously performed dynamic name resolution of constants and variables. As a result, the following performance improvements were achieved:

(Case of 1000 executions of `TCPSocket.new` to the local host)

Rehearsal -----------------------------------------
before   0.031462   0.147946   0.179408 (  0.249279)
after    0.031164   0.146839   0.178003 (  0.346935)
-------------------------------- total: 0.178003sec

            user     system      total        real
before   0.027584   0.138712   0.166296 (  0.233356)
after    0.025953   0.127608   0.153561 (  0.237971)</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This change includes the following updates:
- Added an environment variable `RUBY_TCP_NO_FAST_FALLBACK` to control enabling/disabling fast_fallback
- Updated documentation and man pages
- Revised the implementation of Socket.tcp_fast_fallback= and Socket.tcp_fast_fallback, which previously performed dynamic name resolution of constants and variables. As a result, the following performance improvements were achieved:

(Case of 1000 executions of `TCPSocket.new` to the local host)

Rehearsal -----------------------------------------
before   0.031462   0.147946   0.179408 (  0.249279)
after    0.031164   0.146839   0.178003 (  0.346935)
-------------------------------- total: 0.178003sec

            user     system      total        real
before   0.027584   0.138712   0.166296 (  0.233356)
after    0.025953   0.127608   0.153561 (  0.237971)</pre>
</div>
</content>
</entry>
<entry>
<title>Use ruby_strdup/xfree in fast_fallback</title>
<updated>2024-12-11T23:37:32+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2024-12-11T22:44:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=d84859061a39b81b85bdbae8cfff5088a5c78a93'/>
<id>d84859061a39b81b85bdbae8cfff5088a5c78a93</id>
<content type='text'>
Any memory allocated with xmalloc needs to be matched with xfree rather
than plain free.

Ruby unfortunately redefines strdup to be ruby_strdup, which uses
xmalloc so needs to be xfreed. Previously these were mismatched.

This commit changes the copy to be an explicit ruby_strdup (to avoid
confusion) and the free to be xfree.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Any memory allocated with xmalloc needs to be matched with xfree rather
than plain free.

Ruby unfortunately redefines strdup to be ruby_strdup, which uses
xmalloc so needs to be xfreed. Previously these were mismatched.

This commit changes the copy to be an explicit ruby_strdup (to avoid
confusion) and the free to be xfree.
</pre>
</div>
</content>
</entry>
<entry>
<title>Use `rb_thread_fd_select` instead of select(2) (#12292)</title>
<updated>2024-12-11T09:57:23+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-11T09:57:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f9601903f64e56d95c140074980584c09373b040'/>
<id>f9601903f64e56d95c140074980584c09373b040</id>
<content type='text'>
* Use `rb_thread_fd_select` instead of select(2)

For fixing https://bugs.ruby-lang.org/issues/20932 .
`TCPSocket.new`, which internally uses select(2) for HEv2, can cause SEGV if the number of file descriptors exceeds `FD_SETSIZE`.
This change avoids that issue by replacing select(2) with `rb_thread_fd_select`, which is provided as part of Ruby's internal API.

---

This includes the following changes.

* rb_thread_fd_select does not need common pipe</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Use `rb_thread_fd_select` instead of select(2)

For fixing https://bugs.ruby-lang.org/issues/20932 .
`TCPSocket.new`, which internally uses select(2) for HEv2, can cause SEGV if the number of file descriptors exceeds `FD_SETSIZE`.
This change avoids that issue by replacing select(2) with `rb_thread_fd_select`, which is provided as part of Ruby's internal API.

---

This includes the following changes.

* rb_thread_fd_select does not need common pipe</pre>
</div>
</content>
</entry>
<entry>
<title>Fix Connection Attempt Delay of `Socket.tcp` (#12291)</title>
<updated>2024-12-09T15:08:56+00:00</updated>
<author>
<name>Misaki Shioi</name>
<email>31817032+shioimm@users.noreply.github.com</email>
</author>
<published>2024-12-09T15:08:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=b11287706f691bb5fffede44559132544f553d7f'/>
<id>b11287706f691bb5fffede44559132544f553d7f</id>
<content type='text'>
The following two commits fix the proper clearing of the Connection Attempt Delay in `TCPSocket.new`.

- https://github.com/ruby/ruby/pull/12087/commits/b2f610b0edf8f84d9d0fce038f3ebfa9f2cb0223
- https://github.com/ruby/ruby/pull/12223/commits/6f4efaec5352cdeb6cab86036a83f53c9fa5c3d2

The same fix will be applied to `Socket.tcp`.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The following two commits fix the proper clearing of the Connection Attempt Delay in `TCPSocket.new`.

- https://github.com/ruby/ruby/pull/12087/commits/b2f610b0edf8f84d9d0fce038f3ebfa9f2cb0223
- https://github.com/ruby/ruby/pull/12223/commits/6f4efaec5352cdeb6cab86036a83f53c9fa5c3d2

The same fix will be applied to `Socket.tcp`.</pre>
</div>
</content>
</entry>
<entry>
<title>Fix use of getaddrinfo_shared-&gt;lock</title>
<updated>2024-12-03T18:03:59+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2024-12-03T03:41:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e20904d7cff727f14559acd39f5279fed816553d'/>
<id>e20904d7cff727f14559acd39f5279fed816553d</id>
<content type='text'>
In some locations we were using shared-&gt;lock and in others
&amp;shared-&gt;lock, and we were leaking the allocated memory.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In some locations we were using shared-&gt;lock and in others
&amp;shared-&gt;lock, and we were leaking the allocated memory.
</pre>
</div>
</content>
</entry>
</feed>
