Update LCEssentials+API.swift
This commit is contained in:
@@ -194,7 +194,18 @@ public struct API {
|
|||||||
API.requestLOG(method: method, request: request)
|
API.requestLOG(method: method, request: request)
|
||||||
}
|
}
|
||||||
|
|
||||||
let session = URLSession(
|
// Only spin up a dedicated session (with its own @MainActor
|
||||||
|
// delegate hop for every TLS/auth challenge) when client
|
||||||
|
// certificate auth is actually configured. Creating one of
|
||||||
|
// these per request unconditionally — and never invalidating
|
||||||
|
// it — could stall the async challenge callback waiting on an
|
||||||
|
// already-busy MainActor, hanging the request indefinitely with
|
||||||
|
// no timeout or error ever surfacing. The common case (no
|
||||||
|
// client cert) uses the shared session, which has none of this
|
||||||
|
// risk and is what URLSession is designed to be reused as.
|
||||||
|
let usesCertSession = API.certData != nil
|
||||||
|
let session: URLSession = usesCertSession
|
||||||
|
? URLSession(
|
||||||
configuration: .default,
|
configuration: .default,
|
||||||
delegate: URLSessionDelegateHandler(
|
delegate: URLSessionDelegateHandler(
|
||||||
certData: API.certData,
|
certData: API.certData,
|
||||||
@@ -202,6 +213,12 @@ public struct API {
|
|||||||
),
|
),
|
||||||
delegateQueue: nil
|
delegateQueue: nil
|
||||||
)
|
)
|
||||||
|
: URLSession.shared
|
||||||
|
defer {
|
||||||
|
if usesCertSession {
|
||||||
|
session.finishTasksAndInvalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
let (data, response) = try await session.data(for: request)
|
let (data, response) = try await session.data(for: request)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user