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

Fixup callbacks deadlock when calling callback very frequently #158

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

jhugman
Copy link
Owner

@jhugman jhugman commented Nov 11, 2024

Fixes #157

Minimal test: 146cd39

The change here is in UniffiCallInvoker, reverting the implementation of invokeBlocking back to the Promise based implementation introduced in PR #88.

The deadlock rate for the test is now 0/50.

/cc @tayrevor

Adding any more to the implementation (e.g. uncommenting the console.log) causes the same error as before, but it is completely deterministic:

-- Going to 1024, now at: 264
-- Going to 1024, now at: 265
Assertion failed: (usedDbg_ && "Stats not submitted."), function ~CollectionStats, file HadesGC.cpp, line 259.

On my machine it always stops after 265/1024. I am still unsure if this is a problem with production uniff-bindgen-react-native code, an artifact of the test-harness or something weirder.

I'm going to suggest that this is addressed in a separate issue.

@jhugman jhugman requested a review from zzorba November 11, 2024 17:56
A minimal test which exhibits a deadlock.

On my machine, I can get it to deadlock about 25-35% of the time.

This is with the script:

```sh
fixture=fixtures/callbacks-regression
for i in {1..50} ; do
  echo
  echo "Starting $i"
  cargo xtask run \
    --crate $fixture \
    --ts-dir $fixture/generated \
    --cpp-dir $fixture/generated/cpp \
    $fixture/tests/bindings/test_callbacks_regression.ts
done
```

Counting the incidence of `timed out` in the output and multiplying by 2.

Increasing the work done in the callback (e.g. by uncommenting the `console.log`) gave this error. I'm fairly sure that this is a separate error, and likely an artifact of the test-harness.

```sh
-- Going to 1024, now at: 264
-- Going to 1024, now at: 265
Assertion failed: (usedDbg_ && "Stats not submitted."), function ~CollectionStats, file HadesGC.cpp, line 259.
```

This error is the reason why I can't make a test case to reproduce on CI.

For now, I'm going to treat this error as different to the deadlock.
The change here is in `UniffiCallInvoker`, reverting the implementation of `invokeBlocking` back to the Promise based implementation introduced in PR #88.

The deadlock rate for the test is now 0/50.

Adding any more to the implementation (e.g. uncommenting the `console.log`) causes the same error as before, but it is completely deterministic:

```sh
-- Going to 1024, now at: 264
-- Going to 1024, now at: 265
Assertion failed: (usedDbg_ && "Stats not submitted."), function ~CollectionStats, file HadesGC.cpp, line 259.
```

On my machine it _always_ stops after 265/1024. I am still unsure if this is a problem with production uniff-bindgen-react-native code, an artifact of the test-harness or something weirder.

I'm going to suggest that this is addressed in a separate issue.
@jhugman jhugman force-pushed the jhugman/callbacks-deadlock branch from 2291bbe to 7f61add Compare November 11, 2024 19:26
@trevoranderson
Copy link

This seems like the issue I had. I experienced this both in release builds (XCode archive and run on devices from TestFlight) and locally with a debug build run directly on my iPhone 10s test device.

For reference, this is the stack trace of the hung thread for me.
image

Copy link
Collaborator

@zzorba zzorba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this out, seems to be working great.
LGTM

@jhugman jhugman merged commit bd3fb0f into main Nov 12, 2024
5 checks passed
@jhugman jhugman deleted the jhugman/callbacks-deadlock branch November 12, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Foreign trait / callbacks deadlock
3 participants