GetaddrinfoResolver: don't block EventLoops (#1887)

Motivation:

GetaddrinfoResolver is blocking the calling thread for anything that
uses a `ClientBootstrap`. Often, `ClientBootstrap`s are used on
EventLoops which obviously creates a problem because you mustn't block
EventLoops.

Modifications:

- Offload the `getaddrinfo` call to a `DispatchQueue`.
- Keep the semantics:
  * only do one concurrent `getaddrinfo` call per SelectableEventLoop
  * prevent thread explosion on `SelectableEventLoop`

Result:

Less EL blocking.

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
authored and GitHub committed 2021-07-21 10:22:18 +01:00
1 parent 6e6465de31
commit 40a3794de3
2 files changed
+34 -8

No files matched your search

+2
View File
@@ -365,6 +365,8 @@ public enum SocketAddress: CustomStringConvertible {
/// Creates a new `SocketAddress` for the given host (which will be resolved) and port.
///
/// - warning: This is a blocking call, so please avoid calling this from an `EventLoop`.
///
/// - parameters:
/// - host: the hostname which should be resolved.
/// - port: the port itself