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

Threads in waitInNativeState never gets closed in KMM project. #6339

Open
JohnnyXplor opened this issue Dec 31, 2024 · 8 comments
Open

Threads in waitInNativeState never gets closed in KMM project. #6339

JohnnyXplor opened this issue Dec 31, 2024 · 8 comments
Labels
🐛 Type: Bug ⌛ Waiting for info More information is required

Comments

@JohnnyXplor
Copy link

Version

3.0.0 and above

Summary

Hi guys,
We have a KMM project that uses the Apollo library. It can then run builds for our iOS and Android mobile apps to be consumed. It works well in version 2.x.x. However after we upgraded it to a new version (I tried 3.0.0, 3.8.4 and 4.0.0) it started to have an issue in iOS app where it keeps creating new threads that don't complete. Within a few hours it could create over 2500 threads created, eventually the app would crash. I think it creates the threads to handle the graphql queries (our apps) but somehow those threads are hung there forever.

Some related log:
2 xxx 0x7ce46c (anonymous namespace)::waitInNativeState(_opaque_pthread_cond_t*, _opaque_pthread_mutex_t*) + 68
3 xxx 0x7cd554 Worker::processQueueElement(bool) + 752
4 xxx 0x7cd1c0 (anonymous namespace)::workerRoutine(void*) + 104

Any inputs would be appreciated.

Steps to reproduce the behavior

No response

Logs

(Your logs here)
@martinbonnin
Copy link
Contributor

Thanks for opening this. 2500 threads sounds huge indeed. Are you even running that many queries?

I can try to run thousands of queries on an iOS device, see what's happening but my hunch is that there's something else to it. I'll try that and report back. In the meantime, would you have a reproducer around that would help diagnose this issue?

@martinbonnin
Copy link
Contributor

Tried running 100 queries and I don't get too many threads (reproducer repo here):

Screenshot 2025-01-02 at 15 17 54

A reproducer would help a ton. A thread dump of a few of the extra threads would also be interesting to investigate.

@martinbonnin martinbonnin added the ⌛ Waiting for info More information is required label Jan 2, 2025
@JohnnyXplor
Copy link
Author

Thanks for opening this. 2500 threads sounds huge indeed. Are you even running that many queries?

I can try to run thousands of queries on an iOS device, see what's happening but my hunch is that there's something else to it. I'll try that and report back. In the meantime, would you have a reproducer around that would help diagnose this issue?

Thanks @martinbonnin for looking into it. Yes, there is a timer that triggers a few queries so over time it can be a huge number of queries.

@JohnnyXplor
Copy link
Author

JohnnyXplor commented Jan 5, 2025

Tried running 100 queries and I don't get too many threads (reproducer repo here):

Screenshot 2025-01-02 at 15 17 54

A reproducer would help a ton. A thread dump of a few of the extra threads would also be interesting to investigate.

Hm, I can try. And maybe a dumb question, how did you get your reproducer repo project compiling? it says cannot find "apollo_kotlin_ios_playground" for me.

@martinbonnin
Copy link
Contributor

how did you get your reproducer repo project compiling?

Hi 👋 I just open iosApp in Xcode and break after a few iterations:

Screen.Recording.2025-01-06.at.09.49.09.mov

it says cannot find "apollo_kotlin_ios_playground" for me.

Can you share the full error?

@martinbonnin
Copy link
Contributor

If the error is the import apollo_kotlin_ios_playground line being red in Xcode, this is expected, you need to build the Kotlin framework before it is recognized. This shuold be done automatically with a build phase:

Screenshot 2025-01-06 at 09 53 37

I've just let it run again with 1000 queries and ended up with ~20 threads.

@JohnnyXplor
Copy link
Author

Not sure why, the project doesn't compile for me in Xcode16. I will try to create a reproducer project.

@martinbonnin
Copy link
Contributor

I think this is because the project name wasn't enforced so if you cloned your project under a different directory name, Xcode wouldn't find it. Can you try again with martinbonnin/apollo-kotlin-ios-playground@faa8ce4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug ⌛ Waiting for info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants