expo / custom-expo-updates-server

239 stars 67 forks source link

When using assets the app crashes after loading the update. #3

Closed Stevemoretz closed 2 years ago

Stevemoretz commented 2 years ago

I could manage to get it work without assets, but it crashes with any assets included.

my output example was :

{
    "id": "bf2abe58-3e66-b988-36a0-dbcd3aa6d962",
    "createdAt": "2022-04-02T12:46:24.286Z",
    "runtimeVersion": "1.0.9",
    "assets": [
        {
            "hash": "24272cdaeff82cc5facdaccd982a6f05b60c4504704bbf94c19a6388659880bb",
            "key": "4f1cb2cac2370cd5050681232e8575a8.png",
            "contentType": "image/png",
            "url": "http://localhost:5000/assets?asset=updates/1.0.9/assets/4f1cb2cac2370cd5050681232e8575a8&runtimeVersion=1.0.9&platform=ios"
        }
    ],
    "launchAsset": {
        "hash": "6055338d31f003945e1d46d4042c4525cf60ba042f8b2435dba154b2a69b3272",
        "key": "08d622e8bcd3eee01dc32341f3e25515.bundle",
        "contentType": "application/javascript",
        "url": "http://localhost:5000/assets?asset=updates/1.0.9/bundles/ios-08d622e8bcd3eee01dc32341f3e25515.js&runtimeVersion=1.0.9&platform=ios"
    }
}

Both of the links work, if used manually (with postman for example) but app crashes without even getting the that part.

my local sever requests after opening the app:

GET / 200 714 {} {"host":"localhost:5000","accept":"multipart/mixed,application/expo+json,application/json","expo-channel-name":"preview","expo-runtime-version":"1.0.9","accept-language":"en-us","expo-updates-environment":"BARE","accept-encoding":"gzip, deflate","expo-accept-signature":"false","expo-api-version":"1","user-agent":"otaapp/1 CFNetwork/1220.1 Darwin/19.6.0","expo-json-error":"true","connection":"keep-alive","expo-platform":"ios","expo-release-channel":"default"}

GET / 304 - {} {"host":"localhost:5000","expo-release-channel":"default","accept":"multipart/mixed,application/expo+json,application/json","expo-channel-name":"preview","expo-runtime-version":"1.0.9","accept-language":"en-us","expo-updates-environment":"BARE","accept-encoding":"gzip, deflate","expo-accept-signature":"false","expo-api-version":"1","if-none-match":"W/\"2ca-0pin1zsMeNWCrTQ2vHXxWn6RVt4\"","expo-json-error":"true","user-agent":"otaapp/1 CFNetwork/1220.1 Darwin/19.6.0","expo-platform":"ios","connection":"keep-alive"}

GET /assets?asset=updates/1.0.9/bundles/ios-0848a37c5690604401dfbb0e911bc993.js&runtimeVersion=1.0.9&platform=ios 200 - {} {"host":"localhost:5000","expo-api-version":"1","expo-channel-name":"preview","expo-platform":"ios","expo-updates-environment":"BARE","accept":"/","accept-language":"en-us","user-agent":"otaapp/1 CFNetwork/1220.1 Darwin/19.6.0","accept-encoding":"gzip, deflate","connection":"keep-alive"}


crash log :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[4]' *** First throw call stack: ( 0 CoreFoundation 0x00007fff20421af6 exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48 2 CoreFoundation 0x00007fff2049e77f _CFThrowFormattedException + 194 3 CoreFoundation 0x00007fff2049c9a7 -[NSPlaceholderArray initWithCapacity:].cold.1 + 0 4 CoreFoundation 0x00007fff20323ee6 -[NSPlaceholderArray initWithObjects:count:] + 154 5 CoreFoundation 0x00007fff2040d325 +[NSArray arrayWithObjects:count:] + 40 6 otaapp 0x0000000103504000 -[EXUpdatesDatabase addNewAssets:toUpdateWithId:error:] + 1102 7 otaapp 0x00000001034fe1b6 _29-[EXUpdatesAppLoader <…>

Stevemoretz commented 2 years ago

I guess this happens because updater will load the bundle before loading the assets and it crashes because those assets don't exist while loading the bundle? I'm not sure though. (the third request is the app bundle and the first two are manifest requests. (no assets request is made before the crash))

jonsamp commented 2 years ago

@Stevemoretz Thanks for reporting. I just merged in a change that will fix this. As it turns out, this reference server fell out of sync with our updates protocol. I just updated it in #5. If you have your own custom server, this is the important change to make: https://github.com/expo/custom-expo-updates-server/pull/5/files#diff-63959790760cb7c04d59a6e9c4c5189b9b4a53ee278bf0fbcdc5f4ca153c5d15R57-R58

Stevemoretz commented 2 years ago

@Stevemoretz Thanks for reporting. I just merged in a change that will fix this. As it turns out, this reference server fell out of sync with our updates protocol. I just updated it in #5. If you have your own custom server, this is the important change to make: https://github.com/expo/custom-expo-updates-server/pull/5/files#diff-63959790760cb7c04d59a6e9c4c5189b9b4a53ee278bf0fbcdc5f4ca153c5d15R57-R58

Thank you! Happy to be helpful. Also thanks for explaining.