sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Malformed calls from JS: field sizes are different

Open TheTreek opened this issue 3 years ago • 35 comments

OS:

  • [ ] Windows
  • [x] MacOS
  • [ ] Linux

Platform:

  • [x] iOS
  • [ ] Android

SDK:

  • [x] @sentry/react-native (>= 1.0.0)
  • [ ] react-native-sentry (<= 0.43.2)

SDK version: 4.12.0

react-native version: 0.64.4

Are you using Expo?

  • [ ] Yes
  • [x] No

Are you using sentry.io or on-premise?

  • [x] sentry.io (SaaS)
  • [ ] on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

[Link to issue]

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://[email protected]/...'
  tracesSampleRate: 0.25,
  captureFailedRequestsEnabled: true,
  debug: true,
  enableNdkScopeSync: true,
});

I have following issue:

When calling Sentry.captureMessage("Custom message", 'error') on iOS this error is logged:

 ERROR  Sentry Logger [error]: Error while sending event: [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[42,81],[7,0],[[146,100,1673548149834,false]],379]]

I was able to determine this is happening @sentry/react-native calls RNSentry.captureEnvelope() (node_modules/@sentry/react-native/dist/js/wrapper.js:72). Looks like a react-native bridging issue.

Steps to reproduce:

  • Call Sentry.captureMessage("Custom message here", 'error') on iOS
  • See that it fails to capture the message.

Actual result:

ERROR  Sentry Logger [error]: Error while sending event: [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[42,81],[7,0],[[142,100,1673548954018,false]],354]]

Expected result:

[Expected result]

TheTreek avatar Jan 12 '23 18:01 TheTreek

Thanks for the message.

Here is another issue with the same error and more details about it on Android.

  • https://github.com/getsentry/sentry-react-native/issues/2751

krystofwoldrich avatar Jan 16 '23 10:01 krystofwoldrich

@TheTreek How did you track down the RNSentry.captureEnvelope()? Did you use this?

Could you try to call this code to see what is moduleId 81 and methodId 0?

if (global.__fbBatchedBridge) {
  const origMessageQueue = global.__fbBatchedBridge;
  const modules = origMessageQueue._remoteModuleTable;
  const methods = origMessageQueue._remoteMethodTable;
  global.findModuleByModuleAndMethodIds = (moduleId, methodId) => {
    console.log(`The problematic line code is in: ${modules?.[moduleId]}.${methods?.[moduleId]?.[methodId]}`)
  }
}

global.findModuleByModuleAndMethodIds(81, 0);

krystofwoldrich avatar Jan 26 '23 10:01 krystofwoldrich

@Mkolakoglu Sadly I wasn't able to reproduce the issue after installing the react-redux and redux-logger.

Based on your logs the moduleId.methodId 13.0 and 41.0 could be the issue.

Can you run the following code to decode the modules and method names?

if (global.__fbBatchedBridge) {
  const origMessageQueue = global.__fbBatchedBridge;
  const modules = origMessageQueue._remoteModuleTable;
  const methods = origMessageQueue._remoteMethodTable;
  global.findModuleByModuleAndMethodIds = (moduleId, methodId) => {
    console.log(`The problematic line code is in: ${modules?.[moduleId]}.${methods?.[moduleId]?.[methodId]}`)
  }
}

global.findModuleByModuleAndMethodIds(13, 0);
global.findModuleByModuleAndMethodIds(41, 0);

krystofwoldrich avatar Jan 26 '23 10:01 krystofwoldrich

@JimTeva Based on your logs the module and method ids that could cause the problem are 59 and 0. Could you also try the code above and send us the module name and method name?

krystofwoldrich avatar Jan 26 '23 10:01 krystofwoldrich

@TheTreek How did you track down the RNSentry.captureEnvelope()? Did you use this?

I tracked it down by putting console logs at all the points leading towards RNSentry.captureEnvelope() and saw that there were no logs after RNSentry.captureEnvelope() (on iOS)

Can you run the following code to decode the modules and method names?

I put that code in App.js right after Sentry.init() and got: The problematic line code is in: Timing.createTimer

TheTreek avatar Jan 26 '23 19:01 TheTreek

@krystofwoldrich i've tried running the code after Sentry.init but nothing logged. Tried also at the end of ComponentDidMount in my main component but nothing logged. Where exactly do we run the code above?

JimTeva avatar Jan 27 '23 03:01 JimTeva

@JimTeva Both places you mentioned are okay, are you trying in a dev build? Can you check if global.__fbBatchedBridge exists?

krystofwoldrich avatar Jan 27 '23 09:01 krystofwoldrich

@krystofwoldrich I think I'm getting this same problem.

I ran the same code and got the same @TheTreek in RNSentry.captureEnvelope

I'm using Expo with

"@sentry/react-native": "^4.9.0", "sentry-expo": "~6.0.0"

That's what they recommended for SDK 47


Quick Update: It seems like if I sleep the thread:

      Sentry.Native.captureMessage("def")
      await sleep(200)
      Sentry.Native.captureMessage("foo")

The first will get sent and the second not. This tells me there is something happening in parallel on bootup that's causing Sentry.Native functions to get screwed up. Maybe another library that's overwriting the functions or something?

FWIW, I downgraded to 4.2.2 (which is the next version down with sentry-expo 5.0.3 back from last October and have no problems...so will stick with that until this is resolved.

Aryk avatar Jan 28 '23 01:01 Aryk

@krystofwoldrich I finally got your debug code above to work and the result is the same as @TheTreek:

The problematic line code is in: Timing.createTimer

JimTeva avatar Jan 28 '23 08:01 JimTeva

@Aryk Where do you call the mentioned code? On a button click? Right after Sentry.init?

krystofwoldrich avatar Jan 30 '23 09:01 krystofwoldrich

@JimTeva and @TheTreek sadly the module and method information is less helpful than I hoped for.

Would you be able to create a minimal reproducible example?

krystofwoldrich avatar Jan 30 '23 10:01 krystofwoldrich

@krystofwoldrich Sentry.init is run on the main thread before everything.

This was called in the top level component of the app in a useEffect function, so it was happening on app bootup. I'm 90% sure that it's some library loading in tandem that is conflicting with it as my example suggests.

I rolled back my version of Sentry to 4.2.2 and zero problems so sticking to that. I'm not sure what new stuff got released but don't need any fancy features...just need to report errors to Sentry lol.

Aryk avatar Jan 30 '23 21:01 Aryk

@Aryk Would you be able to create a minimal reproducible example that we could debug the issue on?

krystofwoldrich avatar Jan 31 '23 13:01 krystofwoldrich

@TheTreek and @JimTeva can you guys try running Sentry.captureMessage("test") right after you can Sentry.init and see if that works. That would confirm the thesis that it works at some point and then stops working.

These next few weeks we're crazy swamped with getting a new release out so can't do it soon, but i bet you that @TheTreek and @JimTeva will have the same behavior as what I'm seeing.

Aryk avatar Jan 31 '23 17:01 Aryk

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Feb 22 '23 00:02 github-actions[bot]

I believe I've found the issue. There seems to be a size limit to the parameter we can send over the bridge.

I've filed the envelopeBytes with non-sense data and got the same crash.

ERROR  Sentry Logger [error]: Error while sending event: [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[11,25],[7,0],[[129,100,1677058975393,false]],418]]
for (let i = 0; i < 1e6; i++) {
  envelopeBytes.push(12);
}

await RNSentry.captureEnvelope(envelopeBytes, { store: hardCrashed });

krystofwoldrich avatar Feb 22 '23 09:02 krystofwoldrich

Hello everyone, @TheTreek, @Aryk, @JimTeva, could anyone experiencing this issue confirm if this is happening only in dev builds?

krystofwoldrich avatar Mar 07 '23 12:03 krystofwoldrich

@krystofwoldrich I have not had a chance to upgrade yet, but I will likely be upgrading straight to 5.8 when I upgrade my Expo and maybe the problem will disappear.

Aryk avatar Aug 01 '23 23:08 Aryk

@Aryk Thanks for the update, let us know when you do and if the problem is only in dev or release too.

krystofwoldrich avatar Aug 02 '23 09:08 krystofwoldrich

Hi I am experiencing this also on

  • @sentry/react-native 5.8.0
  • react-native 0.71.12

First time it happened after react-native upgrade

Getting error:

 Sentry Logger [error]: Error while sending event: [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[50,87],[6,0],[[354,100,1691572637387,false]],935]]

I followed this

Output:

LOG The problematic line code is in: RNSentry.captureEnvelope LOG The problematic line code is in: Timing.createTimer

Temp solution ✅

I experimented little bit with init() parameters. I found that it happened only when

debug: true

removing it or switching to false solved the problem I hope it helps someone to resolve it or identify the issue 🤞🏽

dolakzdenek avatar Aug 09 '23 09:08 dolakzdenek