Skip to content

Commit

Permalink
Make sure we create correct socket family. (#334)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lukasa authored and normanmaurer committed Apr 18, 2018
1 parent 56bb5f4 commit 2bce766
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Tests/NIOTests/EventLoopTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public class EventLoopTest : XCTestCase {
let eventLoop = group.next()
let assertHandler = AssertHandler()
let serverSocket = try ServerBootstrap(group: group).bind(host: "localhost", port: 0).wait()
let channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: AF_INET)
let channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: serverSocket.localAddress!.protocolFamily)
try channel.pipeline.add(handler: assertHandler).wait()
_ = try channel.eventLoop.submit {
channel.register().then {
Expand Down

0 comments on commit 2bce766

Please # to comment.