Commit 00cb12b
committed
Replace Timeout.timeout with Socket.tcp(..., open_timeout:)
This patch replaces the implementation of #open_timeout from
Timeout.timeout from the builtin timeout in Socket.tcp, which was
introduced in Ruby 3.5 (https://bugs.ruby-lang.org/issues/21347).
The builtin timeout in Socket.tcp is better in several ways. First, it
does not rely on a separate Ruby Thread for monitoring Timeout (which is
what the timeout library internally does). Also, it is compatible with
Ractors, since it does not rely on Mutexes (which is also what the
timeout library does).
This change allows the following code to work.
require 'net/http'
Ractor.new {
uri = URI('http://example.com/')
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 1
http.get(uri.path)
}.value1 parent 30e6b5f commit 00cb12b
2 files changed
+15
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1654 | 1654 | | |
1655 | 1655 | | |
1656 | 1656 | | |
1657 | | - | |
1658 | | - | |
1659 | | - | |
1660 | | - | |
1661 | | - | |
1662 | | - | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
1663 | 1665 | | |
1664 | | - | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
1665 | 1671 | | |
1666 | 1672 | | |
1667 | 1673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
| 249 | + | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
0 commit comments