Skip to content

Commit 2bce766

Browse files
Lukasanormanmaurer
authored andcommitted
Make sure we create correct socket family. (#334)
Motivation: If a server binds "localhost", and then we try to connect with an AF_INET socket, then on macOS at least some of the time we will have a protocol mismatch, as at least some of the time localhost will have resolved to ::1 before 127.0.0.1. That's bad. Modifications: Create a socket whose address family matches the server's. Result: This test will pass more often
1 parent 56bb5f4 commit 2bce766

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Tests/NIOTests/EventLoopTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public class EventLoopTest : XCTestCase {
307307
let eventLoop = group.next()
308308
let assertHandler = AssertHandler()
309309
let serverSocket = try ServerBootstrap(group: group).bind(host: "localhost", port: 0).wait()
310-
let channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: AF_INET)
310+
let channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: serverSocket.localAddress!.protocolFamily)
311311
try channel.pipeline.add(handler: assertHandler).wait()
312312
_ = try channel.eventLoop.submit {
313313
channel.register().then {

0 commit comments

Comments
 (0)