forcedotcom / SalesforceMobileSDK-ReactNative

BSD 3-Clause "New" or "Revised" License
49 stars 55 forks source link

"Illegal callback invocation from native module." on syncDown #163

Open jpmonette opened 4 years ago

jpmonette commented 4 years ago

Describe the bug When I try to create a new syncDown following registering soup, deleting soup, and registering soup, the app turns into an unrecoverable state (and cannot catch error):

Illegal callback invocation from native module. This callback type only permits a single invocation from native code.

To Reproduce Steps to reproduce the behavior:

// Promise-fying calls + importing salesforce-queries

const sobject = 'Account';
const indexSpecs = ['Id']

const target = {
  type: 'soql',
  query: new SOQL(sobject)
    .select(indexSpecs)
    .limit(10000)
    .build(),
};

const options = { mergeMode: mobileSync.MERGE_MODE.OVERWRITE };

await smartStore.registerSoup(false, sobject, indexSpecs)
await mobileSync.syncDown(false, target, sobject, options, sobject)
await mobileSync.deleteSync(false, sobject)
await smartStore.removeAllStores()
await smartStore.registerSoup(false, sobject, indexSpecs)
await mobileSync.syncDown(false, target, sobject, options, sobject) // boom! 💥

This will throw error + prevent to call syncDown successfully again. Only way is to stop the application + re-build.

Expected behavior Step 6 would allow to run syncDown successfully.

Actual behavior Steps 6 returns:

Illegal callback invocation from native module. This callback type only permits a single invocation from native code.

Versions (please complete the following information):

Trace

RCTFatal
checkCallbackMultipleInvocations(bool*)
__41-[RCTModuleMethod processMethodSignature]_block_invoke_2.106
-[SFMobileSyncReactBridge handleSyncUpdate:withArgs:callback:]
__45-[SFMobileSyncReactBridge syncDown:callback:]_block_invoke
__113-[SFMobileSyncSyncManager(Instrumentation) instr_syncDownWithTarget:options:soupName:syncName:updateBlock:error:]_block_invoke
-[SFSyncTask updateSync:countSynched:]
-[SFAdvancedSyncUpTask syncUpMultipleEntries:recordIds:index:batch:]
-[SFAdvancedSyncUpTask syncUp:recordIds:]
-[SFSyncUpTask runSync:]
-[SFSyncTask run]
__47-[SFMobileSyncSyncManager runSync:updateBlock:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread
wmathurin commented 4 years ago

What version of the Mobile SDK are you running on?

jpmonette commented 4 years ago

@wmathurin v8.1.0

wmathurin commented 4 years ago

I would not call removeAllStores (it deletes all the databases). You could just call removeSoup to drop the sobject soup.

jpmonette commented 4 years ago

How is removeAllStores used then? It seems like it would forever prevent to call syncDown if it's used.

wmathurin commented 4 years ago

removeAllStores wipes everything, including "system" tables that mobile sync relies on. We call it at logout to make sure nothing that belonged to the user was left behind.

aureosouza commented 3 years ago

@wmathurin We are getting the same error after logout and login with different user then logging with first user again in iOS. It seems that the method from native module syncDown is trying to reuse the same callback, which is forbidden by react native doc:

each callback can only be invoked at most one time. A native module can, however, store the callback and invoke it later.

We tried to call removeAllStores on logout but it doesn't help. Would be really good if we could have a guide of which functions are recommended to be called on logout to guarantee any inconsistencies when logging in again. An alternative to callbacks are events which could potentially solve the issue as well.

thiagomouraflima commented 3 years ago

When do you intend to fix this bug?

aureosouza commented 3 years ago

@wmathurin any updates on this? Still have issue as well, thanks!

va1bhav commented 1 year ago

@wmathurin @bhariharan could you please check if you can prioritise this bug into a release? This issue still exists in SDK 10.1.1. Thank you!

MoinJanjua12 commented 7 months ago

HI GUYZ I am also facing the same issue Upon clearing the cache, specifically by removing all stored data and subsequently starting the application, I consistently encounter the following error: "Illegal callback invocation from native module. This callback type only permits a single invocation from native code." this issue only occurs when I navigate the user to the start screen if I restart the app then its work fine any one find any solution?

wmathurin commented 4 months ago

We recommend you stop any running sync before logging out or removing soups or stores. For more information see https://developer.salesforce.com/docs/platform/mobile-sdk/guide/entity-framework-stop-start-sync-operations.html