Repository navigation
Bound TCP resolution and connection waits with real deadlines #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+579
−19
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| require 'socket' | ||
|
|
||
| # A listening socket can queue a connection without a Ruby accept thread. | ||
| # Failures therefore leave no thread blocked in an ensure clause. | ||
| def exchange(host, **options) | ||
| server = TCPServer.new(host, 0) | ||
| client = TCPSocket.new('localhost', server.addr[1], **options) | ||
| accepted = server.accept | ||
| accepted.write("a\0b") | ||
| p [client.remote_address.ip_address == host, client.recvfrom(3)] | ||
| accepted.close | ||
| accepted = nil | ||
| p client.recvfrom(1) # EOF is nil, not a two-element packet. | ||
| ensure | ||
| accepted&.close | ||
| client&.close | ||
| server&.close | ||
| end | ||
|
|
||
| exchange('127.0.0.1', test_mode_settings: {delay: {ipv6: 1000}}) | ||
| exchange('127.0.0.1', test_mode_settings: {error: {ipv6: Socket::EAI_FAIL}}) | ||
| # A deadline for the unresolved family must preserve the IPv4 answer and | ||
| # release the preference wait, even before that answer has been attempted. | ||
| exchange('127.0.0.1', resolv_timeout: 0.01, | ||
| test_mode_settings: {delay: {ipv6: 1000}}) | ||
|
|
||
| # A failed connection does not hide the unresolved family's timeout when | ||
| # there is no usable address or active attempt left. | ||
| closed = TCPServer.new('127.0.0.1', 0) | ||
| port = closed.addr[1] | ||
| closed.close | ||
| begin | ||
| TCPSocket.new('localhost', port, resolv_timeout: 0.01, | ||
| test_mode_settings: {delay: {ipv4: 1000}}) | ||
| rescue IO::TimeoutError | ||
| p :resolution_timeout_after_connection_failure | ||
| end | ||
|
|
||
| [:open_timeout, :resolv_timeout].each do |kind| | ||
| begin | ||
| TCPSocket.new('localhost', 1, **{kind => 0.02}, | ||
| test_mode_settings: {delay: {ipv4: 1000, ipv6: 1000}}) | ||
| rescue IO::TimeoutError | ||
| p kind | ||
| end | ||
| end | ||
|
|
||
| begin | ||
| TCPSocket.new('localhost', 1, open_timeout: 1, connect_timeout: 1) | ||
| rescue ArgumentError | ||
| p :conflicting_timeouts | ||
| end | ||
|
|
||
| server = TCPServer.new('127.0.0.1', 0) | ||
| client = TCPSocket.new('127.0.0.1', server.addr[1], '127.0.0.1', 0, | ||
| connect_timeout: 1, fast_fallback: false) | ||
| accepted = server.accept | ||
| p client.local_address.ip_address == '127.0.0.1' | ||
| client.close | ||
| accepted.close | ||
| server.close | ||
|
|
||
| # Each address comes from getifaddrs; IPv6 scope IDs must survive conversion. | ||
| addresses = Socket.ip_address_list | ||
| p [addresses.any?(&:ipv4_loopback?), addresses.all?(&:ip?), | ||
| addresses.all? { |a| a.ip_port == 0 && a.socktype == 0 }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.