mirror of
https://github.com/yattee/yattee.git
synced 2026-02-21 10:19:46 +00:00
Fix CFNetwork SIGABRT crash when creating download tasks on invalidated session
The background URLSession could be in an invalid state when downloadTask(with:) is called, because invalidateAndCancel() is asynchronous internally. This adds an ObjC exception handler to catch NSExceptions from CFNetwork, nil guards on the session, and safer session lifecycle management (nil after invalidation, finishTasksAndInvalidate for cellular toggle).
This commit is contained in:
@@ -148,8 +148,9 @@ final class DownloadManager: NSObject {
|
||||
self.downloadSettings = settings
|
||||
// Invalidate old session before creating new one with correct settings
|
||||
urlSession?.invalidateAndCancel()
|
||||
urlSession = nil
|
||||
setupSession()
|
||||
|
||||
|
||||
// Resume interrupted downloads only on initial setup
|
||||
if isInitialSetup {
|
||||
resumeInterruptedDownloads()
|
||||
@@ -186,8 +187,9 @@ final class DownloadManager: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Invalidate the old session
|
||||
urlSession.invalidateAndCancel()
|
||||
// 3. Invalidate the old session (use finishTasksAndInvalidate since downloads are already paused)
|
||||
urlSession?.finishTasksAndInvalidate()
|
||||
urlSession = nil
|
||||
|
||||
// 4. Create new session with updated cellular config
|
||||
setupSession()
|
||||
|
||||
Reference in New Issue
Block a user