Skip to content

Use a local TCP server that doesn’t accept connections on macOS for testConnectTimeout() #592

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
merged 2 commits into from
Jun 9, 2022

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Jun 9, 2022

We have observed some test failures on our CI where 198.51.100.254 accepts connection but it shouldn't.
Luckily, this happens only on macOS and we can workaround this by creating a local TCP server with a backlog of 1.
This server will only send a SYN/ACK back to the first connection as it doesn't actually accept the connection. Further connection attempts will not see a SYN/ACK. We can use this behaviour to test a connection timeout on macOS.

The backlog behaviour on Linux can not be used to simulate a non-reachable server. Linux sends a SYN/ACK back even if the backlog queue is full as it has two queues. The second queue is not limit by ChannelOptions.backlog but by /proc/sys/net/ipv4/tcp_max_syn_backlog. We will therefore fallback to 198.51.100.254 on Linux.

@dnadoba dnadoba requested a review from Lukasa June 9, 2022 16:55
@dnadoba
Copy link
Collaborator Author

dnadoba commented Jun 9, 2022

Swift 5.7 & nightly fails because of Sendable warnings.

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jun 9, 2022
@Lukasa Lukasa merged commit 0f21b44 into swift-server:main Jun 9, 2022
@dnadoba dnadoba deleted the dn-fix-test-connect-timeout branch June 9, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants