Instabug-React-Native: setPreSendingHandler seems to be not blocking and sometimes our attachment file is missing

To workaround the addFileAttachment missing bug https://github.com/Instabug/instabug-reactnative/issues/130

We use the addFileAttachment function from native module directly in setPreSendingHandler callback like this

    const InstabugNative = NativeModules.Instabug
    Instabug.setPreSendingHandler(() => {
      const path = fs.DocumentDirectoryPath + '/log.txt'
      fs.exists(path).then((exists: boolean) => {
        if (exists) {
          InstabugNative.addFileAttachment(path)
        }
      })
    })

It works mostly, however we notice that sometimes the log file is not attached. I looked into the callback code

https://github.com/Instabug/instabug-reactnative/blob/5bfd6fab7d2b0b4da3e97d85af9c28877191df8b/ios/RNInstabug/InstabugReactBridge.m#L89-L97

and I wonder how this setPreSendingHandler works? Is it blocking callback, the report submits wait until this callback returns and then really submit? Or does the report submits in async manner?

Let’s assume setPreSendingHandler callback is blocking submit, our native iOS code for attaching file to bug report like this

Instabug background thread
1. Prepare submit
2. Call setPreSendingHandler
3.  + hander attach log file
4. Submit the report

But for this React Native module, as the code in setPreSendingHandler is just

[self sendEventWithName:@"IBGpreSendingHandler" body:nil];

looks like it emits an IBGpreSendingHandler event in JavaScript thread, and as this sendEventWithName function call returns immediately, I guess there is a chance the report is submitted already, and it’s too late for the hander in JavaScript to attach file for the report. Something like this may happen

Instabug background thread                              JavaScript thread
1. Prepare submit
2. Call setPreSendingHandler
3.  + sendEventWithName IBGpreSendingHandler
4. Submit the report
                                                        5. Attach log file

And if we are lucky, the attach log file happens before submit

Instabug background thread                              JavaScript thread
1. Prepare submit
2. Call setPreSendingHandler
3.  + sendEventWithName IBGpreSendingHandler
                                                        4. Attach log file
5. Submit the report

Can youguys confirm this is how it works? And if this is correct, is there any way we can ensure the file is attached to report?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

@Buthrakaur @nasmuris @fangpenlin We just shipped a fix for this in v8.3. Sorry this took a while from our side.

Please open a new issue if you have feedback about it.