Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS hangs inside write transaction with certain nesting of try / catch? #4403

Closed
mfbx9da4 opened this issue Mar 9, 2022 · 9 comments
Closed
Labels
hermes Bugs and features related to running on the React Native hermes engine O-Community T-Bug

Comments

@mfbx9da4
Copy link

mfbx9da4 commented Mar 9, 2022

How frequently does the bug occur?

All the time

Description

I am experiencing a similar issue to #2434.

Where I do something like

async function trySendMessage(message) {
  try {
    await sendMessage(message);
  } catch (error) {
    await handleError(error);
  }
}

async function sendMessage(message) {
  await doSendMessage(message);
}

async function handleError(message, error) {
  realm.write(() => {
    message.error = error;
   // ❌  ❌  JS task hangs on this line and never continues. The message is never updated in realm.
  });
}

by refactoring to

async function trySendMessage(message) {
  try {
    await sendMessage(message);
  } catch (error) {
    console.log(error);
  }
}

async function sendMessage(message) {
  try {
    await doSendMessage(message);
  } catch (error) {
    realm.write(() => {
      message.error = error;
    });
  }
}

Realm seems to have some issues with async functions see #4375 . Could this be related to JSI hanging issues? facebook/react-native#33006

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

I appreciate the sample code is not a fully reproducible example so it's okay if this issue gets closed. However, I imagine the core developers might have seen an issue like this before and might be able to provide workarounds.

Version

10.20.0-beta.2

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

ios

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@mfbx9da4 mfbx9da4 added the T-Bug label Mar 9, 2022
@mfbx9da4 mfbx9da4 changed the title JS thread hangs inside write transaction JS hangs inside write transaction Mar 9, 2022
@kneth
Copy link
Contributor

kneth commented Mar 10, 2022

Could this be related to JSI hanging issues?

We are definitely also experience that issue. But you could try to use 10.13.0 instead of 10.20.0-beta.2 to validate the hypothesis.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Mar 10, 2022
@mfbx9da4
Copy link
Author

mfbx9da4 commented Mar 10, 2022

Unfortunately, I don't think I can use 10.13.0 as I was experiencing this issue #3837 and upgrading fixed it for me.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Mar 10, 2022
@sync-by-unito sync-by-unito bot added the hermes Bugs and features related to running on the React Native hermes engine label Mar 16, 2022
@tomduncalf
Copy link
Contributor

tomduncalf commented Mar 23, 2022

Hey @mfbx9da4, thanks for the report.

I don't think this is related to the JSI hanging issues – as I mentioned in the issue, we've found that calling React Native's JSIExectuor::flush solves this one, although we haven't merged this fix yet.

I tried to reproduce this issue based on the information you provided, but couldn't see it hanging. Could you please take a look at my reproduction repo at https://github.com/tomduncalf/4403-hang-in-write to see what might be different from your implementation?

When I run node index.js, I see:

Handling error
Handled error

then it exits, as you'd expect. If the implementation looks to be equivalent to yours then I can try a React Native version to see if it's an exclusively RN issue.

Equally if you are able to provide a minimal reproduction repo, that would be helpful!

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Mar 23, 2022
@cristianoccazinsp
Copy link

Commenting here to get some notifications. I cannot say precisely I've seen the issue, but I've definitely seen JSI hangs both while developing and from production freeze logs. I wasn't able to pinpoint the exact issue but perhaps this is related!

I will add more info if I manage to reproduce it consistently.

@tomduncalf
Copy link
Contributor

Thanks @cristianoccazinsp – I guess it's #3571 which you are referring to (where the UI freezes), which I think is a different issue (though I could be wrong). We're hoping to have a fix for that one soon, we know what the fix is and it just needs a bit of finessing so I will update that ticket when we have released it!

@mfbx9da4
Copy link
Author

Sounds like a different issue. I'm sorry I haven't had the time to replicate, it's on my backlog!

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Mar 26, 2022
@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Mar 28, 2022
@mfbx9da4 mfbx9da4 changed the title JS hangs inside write transaction JS hangs inside write transaction with certain nesting of try / catch? Apr 24, 2022
@takameyer
Copy link
Contributor

@mfbx9da4 Are you able to replicate this?

@mfbx9da4
Copy link
Author

No, I haven't had the time to isolate this and @tomduncalf 's code also works fine on React native so feel free to close. I doubt I will dedicate the time to isolate the issue near term.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels May 12, 2022
@tomduncalf
Copy link
Contributor

Thanks @mfbx9da4.

If anyone else is encountering this issue and is able to supply reproduction code (or can reproduce the issue with the sample repo linked in this comment), please feel free to reopen this issue with more details and a link to the reproduction.

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label May 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hermes Bugs and features related to running on the React Native hermes engine O-Community T-Bug
Projects
None yet
Development

No branches or pull requests

5 participants