Back

muilti threads data race appwrtie realtime

  • 1
  • Apple
  • Realtime
ROAD 6
29 Dec, 2023, 19:31

hi i have problem with my realtime subscription somone can help ? all i did is to write subscription func and call the realtime.subscribe

TL;DR
Summary: The user is experiencing a data race issue when using the Appwrite Realtime Library with Swift. The problem occurs when triggering the realtime subscription methods and sometimes crashes the app. The user suspects it is a bug in the library. They have provided code samples and details about their environment. They mention using the thread sanitizer tool in Xcode and suggest trying different versions of the SDK. They also mention that the issue occurs in Appwrite versions 2.0.0 and above. They provide a link to a repository for reproducing the error. Solution (if applicable): No solution is provided in the thread.
D5
29 Dec, 2023, 22:38

Is this cloud or self-hosted?

ROAD 6
30 Dec, 2023, 09:39

cloud

D5
30 Dec, 2023, 12:39

Could you please share the full code?

ROAD 6
30 Dec, 2023, 14:38

i removed a lot of code to debug this and here is the minimum code for the data race error to show i have manager variable inside the MainCV view and when the page is appear im triggering the subscriptions(realtime) method and thats making the data race (error)

ROAD 6
30 Dec, 2023, 14:45
ROAD 6
31 Dec, 2023, 20:51

?

D5
31 Dec, 2023, 22:26

I practically didn't have used Swift, but this doesn't look like an error?

ROAD 6
1 Jan, 2024, 10:39

its data race leak -> two different threads (main,global) running the same thing (web-socket connect), its only happening when triggering one of the realtime appwrite subscription methods from the (appwrtie - swift - sdk), and sometimes its crashing the app. from my research i pretty sure its bug inside the Appwrtie Realtime Libary so how we can overcome this ?

Drake
4 Jan, 2024, 23:39

how do i turn on xcode thread sanitizer tool? I don't use Xcode so i don't know where anything is 😬

Drake
4 Jan, 2024, 23:40

nvm i think i found it

Drake
4 Jan, 2024, 23:50

soooo where exactly do you see the error? I see

Drake
4 Jan, 2024, 23:52
Drake
4 Jan, 2024, 23:53

i subscribed and then went to the console and deleted a document in my collection

ROAD 6
5 Jan, 2024, 10:25

i made a new SwiftUI project for reproduce the error for you on blank project this is the easy steps i did

  1. turn on thread sanitizer tool click on app icon -> edit scheme -> diagnostics -> thread sanitizer tool
  2. add Appwrtie class with subscribe method same as the Appwrtie apple doc
  3. make appwrite state variable inside the ContentView and call the subscribe method from it run the app and you can see the data race problem
ROAD 6
5 Jan, 2024, 10:35

im using SwiftUI not UIKit and i find out its showing from Appwrite version 2.0.0 until today version... the fastest way to see what im talking about you you can use https://github.com/appwrite/playground-for-apple-swiftui just change the Appwrite version above 2.0.0 and turn Thread sanitizer tool on

Drake
5 Jan, 2024, 16:53

thanks! ill take a look

Drake
5 Jan, 2024, 16:54

are you saying the problem is not present in version 1.2.3 of the SDK?

ROAD 6
5 Jan, 2024, 17:09

hey Steven i tried 1.0.0 and didn't saw the issue and 2.0.0 and above i saw it i now checked specific for version 1.2.3 of the SDK with https://github.com/appwrite/playground-for-apple-swiftui when clicking on subscribe the data race Appears

Drake
5 Jan, 2024, 17:20

thanks for the insight! The only thing i found related between 1.0.0 and 1.2.3 was this: https://github.com/appwrite/sdk-for-apple/pull/28/files#diff-004b903953dedf993743db9d8325f4ddf63abe7a51fbee81f243e9216ca22e7e

ROAD 6
5 Jan, 2024, 18:00

i see i don't understanding why it's happened from the changes you shared from the console what i see is some data write and the heap block allocated from thread 2 and the same data read from thread 1 i guess in the same time because its data race issue Hopefully we can trace it because i don’t think its will pass the Apple App Store check

Drake
5 Jan, 2024, 18:02

Honestly, I'm not sure either since I don't know too much about swift...let me see if anyone else on the team does

ROAD 6
7 Jan, 2024, 10:43

hey steven any updates from anyone on the team is familiar with swift? i think it's critical for the Appwrite Apple SDK to work well for swift developers to use it

Jake
8 Jan, 2024, 06:17

Hey, sorry you're having trouble with the SDK, a few questions first off:

  • Have you tried with the latest version of the SDK (4.0.2)?
  • Have you tried calling from a class instead of an actor? (subscribe is a synchronous method)
  • Which version of Xcode are you using?
  • Have you recently updated Xcode?
  • Does this warning trigger for both simulators and physical devices?
ROAD 6
8 Jan, 2024, 08:44

hey Jake, firstable my answers is -> 1,2,4) all yes 3) my xcode Version is 15.1 5) with physical device we can’t unable the thread saintizer tool, i checked with https://github.com/appwrite/playground-for-apple-swiftui for easier way for you to reproduce it just turn on the thread saintizer tool and change to the latest swift sdk version.

i think its important to understand only when turn on this tool the problem is showing. this is tool is created for trace data race issues and the only method in the SDK trigger the issue is the subscribe method i think if someone on the team is familiar with the WebSocket file inisde the swift sdk will see the error it will be more easier to understand what why its popping hey Jake, firstable my answers is -> 1,2,4) all yes 3) my xcode Version is 15.1 5) with physical device we can’t unable the thread saintizer tool, i checked with https://github.com/appwrite/playground-for-apple-swiftui for easier way for you to reproduce it just turn on the thread saintizer tool and change to the latest swift sdk version.

i think its important to understand only when turn on this tool the problem is showing. this is tool is created for trace data race issues and the only method in the SDK trigger the issue is the subscribe method i think if someone on the team is familiar with the WebSocket file inisde the swift sdk will see the error it will be more easier to understand what why its popping

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more