From c627e97248d1c4645017f33bac1a4b0f8b6e6f42 Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Mon, 23 Oct 2023 17:11:42 -0700 Subject: [PATCH 1/2] Provide default, and allow customizing, timeout interval of event source requests --- Sources/Sunday/EventSource.swift | 2 +- Sources/Sunday/NetworkRequestFactory.swift | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/Sunday/EventSource.swift b/Sources/Sunday/EventSource.swift index 3575b478..17afec80 100644 --- a/Sources/Sunday/EventSource.swift +++ b/Sources/Sunday/EventSource.swift @@ -494,7 +494,7 @@ public class EventSource { return } - // Quietly close dure to Task or URLTask cancellation + // Quietly close due to Task or URLTask cancellation if isCancellationError(error: error) { fireErrorEvent(error: error) close() diff --git a/Sources/Sunday/NetworkRequestFactory.swift b/Sources/Sunday/NetworkRequestFactory.swift index a20aea56..e67fc9ce 100644 --- a/Sources/Sunday/NetworkRequestFactory.swift +++ b/Sources/Sunday/NetworkRequestFactory.swift @@ -26,6 +26,8 @@ private let eventStreamLogger = Logger.for(category: "Event Streams") public class NetworkRequestFactory: RequestFactory { + public static let eventRequestTimeoutInterval: TimeInterval = 15 * 60 // 15 minutes + public let baseURL: URI.Template public let session: NetworkSession public let eventSession: NetworkSession @@ -34,6 +36,7 @@ public class NetworkRequestFactory: RequestFactory { public let mediaTypeEncoders: MediaTypeEncoders public let mediaTypeDecoders: MediaTypeDecoders public let pathEncoders: PathEncoders + public let eventRequestTimeoutInterval: TimeInterval private var problemTypes: [String: Problem.Type] = [:] public init( @@ -44,6 +47,7 @@ public class NetworkRequestFactory: RequestFactory { requestQueue: DispatchQueue = .global(qos: .utility), mediaTypeEncoders: MediaTypeEncoders = .default, mediaTypeDecoders: MediaTypeDecoders = .default, + eventRequestTimeoutInterval: TimeInterval = NetworkRequestFactory.eventRequestTimeoutInterval, pathEncoders: PathEncoders = .default ) { self.baseURL = baseURL @@ -54,6 +58,7 @@ public class NetworkRequestFactory: RequestFactory { self.mediaTypeEncoders = mediaTypeEncoders self.mediaTypeDecoders = mediaTypeDecoders self.pathEncoders = pathEncoders + self.eventRequestTimeoutInterval = eventRequestTimeoutInterval } public convenience init( @@ -452,7 +457,11 @@ public class NetworkRequestFactory: RequestFactory { return EventSource(queue: requestQueue) { headers in guard let request = try await requestFactory() else { return nil } - return try self.eventSession.dataEventStream(for: request.adding(httpHeaders: headers)) + let updatedRequest = + request + .adding(httpHeaders: headers) + .with(timeoutInterval: self.eventRequestTimeoutInterval) + return try self.eventSession.dataEventStream(for: updatedRequest) } } From 839803e992a83caba1c3f5726f2e6e02dd733d3e Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Mon, 23 Oct 2023 20:19:35 -0700 Subject: [PATCH 2/2] Set pkg clone directory to work around PIF error --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b7c1c36a..d63a7a40 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ define buildtest xcodebuild -scheme $(project)-Package \ -derivedDataPath .derived-data/$(1) -resultBundleVersion 3 -resultBundlePath ./TestResults/$(1) -destination '$(2)' \ -enableCodeCoverage=YES -enableAddressSanitizer=YES -enableThreadSanitizer=YES -enableUndefinedBehaviorSanitizer=YES \ + -clonedSourcePackagesDirPath ${HOME}/.xcode-pkgs \ test | xcbeautify endef