forcedotcom / SalesforceMobileSDK-iOS

iOS SDK for Salesforce
Other
537 stars 419 forks source link

Application Crashed on Alter soups #3735

Closed mahipalsingh-syt closed 1 month ago

mahipalsingh-syt commented 2 months ago

Please fill out the following details:

  1. Version of Mobile SDK Used: 10.0.0
  2. Issue found in Native App or Hybrid App: Hybrid
  3. OS Version: 15.5 / 17.2
  4. Device: iPad
  5. Steps to reproduce: randomly crashing on different different soup
  6. Actual behavior: alterSoup crashing application while syncing
  7. Expected Behavior: while alterSoup it should alter successfully
  8. Error Log:
Result: UNIQUE constraint failed: TABLE_19.id
At line 1:
INSERT INTO TABLE_19 (id,created,lastModified,soup,TABLE_19_1,TABLE_19_0,TABLE_19_2) SELECT id,created,lastModified,soup,TABLE_19_1,TABLE_19_0,TABLE_19_2 FROM TABLE_19_old

When we reSync Application it got crashed and unable to launch application.

configList.forEach((soupDetails: SoupType.SoupDetails, index: number) => {
          mobilesync.getSyncStatus(
            {},
            soupDetails.syncName[0],
            (sync: any) => {
              if (sync === null) {
                smartstore.registerSoup(
                  false,
                  soupDetails.soupName,
                  soupDetails.indexes,
                  () => {
                    // keeping empty as we are only registering
                    if (index === configList.length - 1) {
                      resolve(true);
                    }
                  },
                  (error) => {
                    reject(error);
                  }
                );
              } else {
                smartstore.alterSoup(
                  {},
                  soupDetails.soupName,
                  soupDetails.indexes,
                  true,
                  () => {
                    resolve(true);
                  },
                  () => {
                    resolve(true);
                  }
                );
              }
            },
            (error: any) => {
              reject(error);
            }
          );
        })

Platform: iOS "sdkDependencies": { "SalesforceMobileSDK-Android": "https://github.com/forcedotcom/SalesforceMobileSDK-Android.git#v10.0.0", "SalesforceMobileSDK-iOS": "https://github.com/forcedotcom/SalesforceMobileSDK-iOS.git#v10.0.0" }, "react-native": "0.67.5", "react-native-force": "git+https://github.com/forcedotcom/SalesforceMobileSDK-ReactNative.git#v10.0.0"

wmathurin commented 2 months ago

It looks like you are firing multiple calls to registerSoup or alterSoup in parallel. You should rewrite your code to do the register/alter soup for each soup details once the previous one completed. So have a method that take the index and call itself with index + 1 in the success callback.

wmathurin commented 1 month ago

Closing the issue - make sure to serialize your alterSoup calls as suggested above.