Cap-go / capacitor-updater

Live update for capacitor apps
https://capgo.app
Mozilla Public License 2.0
502 stars 105 forks source link

bug: iOS Simultaneous accesses to 0x60000023c990, but modification requires exclusive access #344

Closed ehiosunbishop closed 4 months ago

ehiosunbishop commented 5 months ago

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.7.4
  @capacitor/core: 5.7.4
  @capacitor/android: 5.7.4
  @capacitor/ios: 5.7.4

Installed Dependencies:

  @capacitor/cli: 5.5.1
  @capacitor/ios: 5.7.4
  @capacitor/android: 5.7.4
  @capacitor/core: 5.7.4

[success] iOS looking great! 👌
[success] Android looking great! 👌

Plugin Version

"@capgo/capacitor-updater": "^5.7.18"

context(s)

ManualModel: true
AutoMode: false
CapgoCloud: false
OnPremise: true

Platform(s)

iOS - iphone and simulators

Current Behavior

While downloading the app crashes at 75% of download and xcode pause at the this code block `private func saveDownloaded(sourceZip: URL, id: String, base: URL) throws { try prepareFolder(source: base) let destHot: URL = base.appendingPathComponent(id) let destUnZip: URL = documentsDir.appendingPathComponent(randomString(length: 10))

    self.unzipPercent = 0
    self.notifyDownload(id, 75)

    var unzipError: NSError?
    let success = SSZipArchive.unzipFile(atPath: sourceZip.path,
                                         toDestination: destUnZip.path,
                                         preserveAttributes: true,
                                         overwrite: true,
                                         nestedZipLevel: 1,
                                         password: nil,
                                         error: &unzipError,
                                         delegate: nil,
                                         progressHandler: { [weak self] (entry, zipInfo, entryNumber, total) in
                                            guard let self = self else { return }
                                            self.unzipProgressHandler(entry: entry, zipInfo: zipInfo, entryNumber: entryNumber, total: total, destUnZip: destUnZip, id: id, unzipError: &unzipError)
                                         },
                                         completionHandler: nil)

` image

Expected Behavior

Download zip file without crashing

Code Reproduction

`
const appUpdate = await CapacitorUpdater.download({ url: 'https://github.com/ehiosunbishop/live-update-testerx/raw/main/www.zip', version });

return appUpdate;

` image

ehiosunbishop commented 5 months ago

Downgrading the plugin version to 5.6.13 worked for me..

which was kinda strange

danielgottbehuet commented 5 months ago

I've been experiencing the same issue since yesterday. I updated from ^5.3.48 to ^5.7.17. I'll try downgrading.

Bildschirmfoto 2024-03-26 um 15 52 42
rajild commented 4 months ago

Downgrading the plugin version to 5.6.13 worked for me..

which was kinda strange

Using 5.6.13 but having same issue. Issue is on iOS, working in Android.

✨ Capacitor-updater: Stats sent for download_60, version 24.3.2 ✨ Capacitor-updater: Cannot found privateKey or sessionKey Simultaneous accesses to 0x600002c44a90, but modification requires exclusive access. Previous access (a modification) started at ⚡️ TO JS

I'm using auto update from my server.

rajild commented 4 months ago

Below is full log that may be helpful in debugging:

✨ Capacitor-updater: Check for pending update ✨ Capacitor-updater: Stats sent for app_moved_to_background, version builtin ⚡️ [log] - Application pause ⚡️ TO JS undefined ✨ Capacitor-updater: Wait for 10000 ms, then check for notifyAppReady ✨ Capacitor-updater: Check for update via https://ws1.wealthspectrum.com/wealthspectrum/app/mobile/checkForUpdate ✨ Capacitor-updater: Auto-update parameters: InfoObject(platform: Optional("ios"), device_id: Optional("92FDB34A-3D6B-4695-8F06-926F5B4E2BED"), app_id: Optional("com.wealthspectrum.wealth.portal"), custom_id: Optional(""), version_build: Optional("24.3"), version_code: Optional("9"), version_os: Optional("17.0.1"), version_name: Optional("builtin"), plugin_version: Optional("5.7.14"), is_emulator: Optional(true), is_prod: Optional(false), action: nil, channel: nil, defaultChannel: Optional("")) ⚡️ [log] - Application resumed : 1711634133899 ⚡️ [log] - vault kept unlocked ✨ Capacitor-updater: Stats sent for app_moved_to_foreground, version builtin ✨ Capacitor-updater: New bundle: 24.3.2 found. Current is: builtin. Update will occur next time app moves to background. ✨ Capacitor-updater: list File : /Users/appliedm1/Library/Developer/CoreSimulator/Devices/2FC07F16-5D1D-4461-B417-9E742CFF46E5/data/Containers/Data/Application/75163DDB-5940-4142-BA31-410B92BA2A8D/Documents/versions ✨ Capacitor-updater: Storing info for bundle [0Ur9YqzhTw] { "id": "0Ur9YqzhTw", "version": "24.3.2", "downloaded": "2024-03-28T13:55:42.480Z", "checksum": "", "status": "downloading"} ✨ Capacitor-updater: Stats sent for download_0, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_10, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_10, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_20, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_20, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_30, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_40, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_40, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_50, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_50, version 24.3.2 ✨ Capacitor-updater: Cannot found privateKey or sessionKey ✨ Capacitor-updater: Stats sent for download_60, version 24.3.2 Simultaneous accesses to 0x600000bd55d0, but modification requires exclusive access. Previous access (a modification) started at CapgoCapacitorUpdater`CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 1544 (0x1064255e4). Current access (a modification) started at: 0 libswiftCore.dylib 0x0000000107b8117c swift::runtime::AccessSet::insert(swift::runtime::Access, void, void*, swift::ExclusivityFlags) + 428 1 libswiftCore.dylib 0x0000000107b81390 swift_beginAccess + 72 2 CapgoCapacitorUpdater 0x0000000106425c6c closure #1 in CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 284 3 CapgoCapacitorUpdater 0x000000010643df30 partial apply for closure #1 in CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 156 4 CapgoCapacitorUpdater 0x0000000106425ddc thunk for @escaping @callee_guaranteed (@guaranteed String, @unowned unz_file_info_s, @unowned Int, @unowned Int) -> () + 224 5 SSZipArchive 0x0000000105f4aebc +[SSZipArchive unzipFileAtPath:toDestination:preserveAttributes:overwrite:nestedZipLevel:password:error:delegate:progressHandler:completionHandler:] + 7020 6 CapgoCapacitorUpdater 0x0000000106424fdc CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 1660 7 CapgoCapacitorUpdater 0x0000000106429d34 closure #3 in CapacitorUpdater.download(url:version:sessionKey:) + 1596 8 CapgoCapacitorUpdater 0x000000010642aea4 partial apply for closure #3 in CapacitorUpdater.download(url:version:sessionKey:) + 72 9 Alamofire 0x00000001060194e0 closure #1 in closure #1 in closure #3 in closure #1 in DownloadRequest._response(queue:responseSerializer:completionHandler:) + 124 10 Alamofire 0x0000000105fb0228 thunk for @escaping @callee_guaranteed @Sendable () -> () + 48 11 libdispatch.dylib 0x00000001081fc0d8 _dispatch_call_block_and_release + 24 12 libdispatch.dylib 0x00000001081fd92c _dispatch_client_callout + 16 13 libdispatch.dylib 0x0000000108211348 _dispatch_root_queue_drain + 940 14 libdispatch.dylib 0x0000000108211f68 _dispatch_worker_thread2 + 256 15 libsystem_pthread.dylib 0x0000000108d2b808 _pthread_wqthread + 224 16 libsystem_pthread.dylib 0x0000000108d2a6dc start_wqthread + 8

rajild commented 4 months ago

Below is full log that may be helpful in debugging:

✨ Capacitor-updater: Check for pending update ✨ Capacitor-updater: Stats sent for app_moved_to_background, version builtin ⚡️ [log] - Application pause ⚡️ TO JS undefined ✨ Capacitor-updater: Wait for 10000 ms, then check for notifyAppReady ✨ Capacitor-updater: Check for update via https://ws1.wealthspectrum.com/wealthspectrum/app/mobile/checkForUpdate ✨ Capacitor-updater: Auto-update parameters: InfoObject(platform: Optional("ios"), device_id: Optional("92FDB34A-3D6B-4695-8F06-926F5B4E2BED"), app_id: Optional("com.wealthspectrum.wealth.portal"), custom_id: Optional(""), version_build: Optional("24.3"), version_code: Optional("9"), version_os: Optional("17.0.1"), version_name: Optional("builtin"), plugin_version: Optional("5.7.14"), is_emulator: Optional(true), is_prod: Optional(false), action: nil, channel: nil, defaultChannel: Optional("")) ⚡️ [log] - Application resumed : 1711634133899 ⚡️ [log] - vault kept unlocked ✨ Capacitor-updater: Stats sent for app_moved_to_foreground, version builtin ✨ Capacitor-updater: New bundle: 24.3.2 found. Current is: builtin. Update will occur next time app moves to background. ✨ Capacitor-updater: list File : /Users/appliedm1/Library/Developer/CoreSimulator/Devices/2FC07F16-5D1D-4461-B417-9E742CFF46E5/data/Containers/Data/Application/75163DDB-5940-4142-BA31-410B92BA2A8D/Documents/versions ✨ Capacitor-updater: Storing info for bundle [0Ur9YqzhTw] { "id": "0Ur9YqzhTw", "version": "24.3.2", "downloaded": "2024-03-28T13:55:42.480Z", "checksum": "", "status": "downloading"} ✨ Capacitor-updater: Stats sent for download_0, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_10, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_10, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_20, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_20, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_30, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_40, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_40, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_50, version 24.3.2 ✨ Capacitor-updater: Stats sent for download_50, version 24.3.2 ✨ Capacitor-updater: Cannot found privateKey or sessionKey ✨ Capacitor-updater: Stats sent for download_60, version 24.3.2 Simultaneous accesses to 0x600000bd55d0, but modification requires exclusive access. Previous access (a modification) started at CapgoCapacitorUpdater`CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 1544 (0x1064255e4). Current access (a modification) started at: 0 libswiftCore.dylib 0x0000000107b8117c swift::runtime::AccessSet::insert(swift::runtime::Access, void, void*, swift::ExclusivityFlags) + 428 1 libswiftCore.dylib 0x0000000107b81390 swift_beginAccess + 72 2 CapgoCapacitorUpdater 0x0000000106425c6c closure #1 in CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 284 3 CapgoCapacitorUpdater 0x000000010643df30 partial apply for closure #1 in CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 156 4 CapgoCapacitorUpdater 0x0000000106425ddc thunk for @escaping @callee_guaranteed (@guaranteed String, @unowned unz_file_info_s, @unowned Int, @unowned Int) -> () + 224 5 SSZipArchive 0x0000000105f4aebc +[SSZipArchive unzipFileAtPath:toDestination:preserveAttributes:overwrite:nestedZipLevel:password:error:delegate:progressHandler:completionHandler:] + 7020 6 CapgoCapacitorUpdater 0x0000000106424fdc CapacitorUpdater.saveDownloaded(sourceZip:id:base:) + 1660 7 CapgoCapacitorUpdater 0x0000000106429d34 closure #3 in CapacitorUpdater.download(url:version:sessionKey:) + 1596 8 CapgoCapacitorUpdater 0x000000010642aea4 partial apply for closure #3 in CapacitorUpdater.download(url:version:sessionKey:) + 72 9 Alamofire 0x00000001060194e0 closure #1 in closure #1 in closure #3 in closure #1 in DownloadRequest._response(queue:responseSerializer:completionHandler:) + 124 10 Alamofire 0x0000000105fb0228 thunk for @escaping @callee_guaranteed @sendable () -> () + 48 11 libdispatch.dylib 0x00000001081fc0d8 _dispatch_call_block_and_release + 24 12 libdispatch.dylib 0x00000001081fd92c _dispatch_client_callout + 16 13 libdispatch.dylib 0x0000000108211348 _dispatch_root_queue_drain + 940 14 libdispatch.dylib 0x0000000108211f68 _dispatch_worker_thread2 + 256 15 libsystem_pthread.dylib 0x0000000108d2b808 _pthread_wqthread + 224 16 libsystem_pthread.dylib 0x0000000108d2a6dc start_wqthread + 8

Found this is working fine on latest version.

slkgtr commented 4 months ago

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/memorysafety/

Example to avoid call twins It works for me but i don't know any side-effect to change like this.

private func saveDownloaded(sourceZip: URL, id: String, base: URL) throws { ..... DispatchQueue.main.async { var unzipError1 = unzipError self.unzipProgressHandler(entry: entry, zipInfo: zipInfo, entryNumber: entryNumber, total: total, destUnZip: destUnZip, id: id, newUnzipError: &unzipError1) } ...... }

private func unzipProgressHandler(entry: String, zipInfo: unz_file_info, entryNumber: Int, total: Int, destUnZip: URL, id: String, newUnzipError: inout NSError?) {

and change unzipError to newUnzipError


Find SSZipArchive

...... if (progressHandler1) { progressHandler1(strPath, fileInfo, currentFileNumber, globalInfo.number_entry); } } } while (ret == UNZ_OK && success);

// Close
unzClose(zip);

........

eljass commented 4 months ago

The code throwing the issue has been changed in the latest version and at least for us the version ^5.9.2 seems to work on iOS