Skip to content

Commit 9401037

Browse files
authored
Make syncShutdown unavailable from async (#667)
* Make syncShutdown unavailable from async Motivation syncShutdown can cause unbounded thread blocking, we shouldn't allow it in concurrent code. Modification Mark syncShutdown unavailable from async. Result Users are warned if they try to syncShutdown in an async context * Only noasync on 5.7
1 parent 1d24271 commit 9401037

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
6363
}
6464
```
6565

66-
You should always shut down `HTTPClient` instances you created using `try httpClient.syncShutdown()`. Please note that you must not call `httpClient.syncShutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
66+
You should always shut down `HTTPClient` instances you created using `try httpClient.shutdown()`. Please note that you must not call `httpClient.shutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
6767

6868
### async/await examples
6969

Sources/AsyncHTTPClient/Docs.docc/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
7171
}
7272
```
7373

74-
You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/syncShutdown()``. Please note that you must not call ``HTTPClient/syncShutdown()`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
74+
You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/shutdown()-96ayw()``. Please note that you must not call ``HTTPClient/shutdown()-96ayw()`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
7575

7676
### async/await examples
7777

Sources/AsyncHTTPClient/HTTPClient.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,29 @@ public class HTTPClient {
139139
""")
140140
case .upAndRunning:
141141
preconditionFailure("""
142-
Client not shut down before the deinit. Please call client.syncShutdown() when no \
142+
Client not shut down before the deinit. Please call client.shutdown() when no \
143143
longer needed. Otherwise memory will leak.
144144
""")
145145
}
146146
}
147147
}
148148

149+
#if swift(>=5.7)
149150
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
151+
///
152+
/// This method blocks the thread indefinitely, prefer using ``shutdown()-96ayw``.
153+
@available(*, noasync, message: "syncShutdown() can block indefinitely, prefer shutdown()", renamed: "shutdown()")
154+
public func syncShutdown() throws {
155+
try self.syncShutdown(requiresCleanClose: false)
156+
}
157+
#else
158+
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
159+
///
160+
/// This method blocks the thread indefinitely, prefer using ``shutdown()-96ayw``.
150161
public func syncShutdown() throws {
151162
try self.syncShutdown(requiresCleanClose: false)
152163
}
164+
#endif
153165

154166
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
155167
///

0 commit comments

Comments
 (0)