Data stored using Storage API suddenly disappearing, returning blank arrays

So for the last month or so i’ve been building a custom calendar that uses the Storage API to store the calendar events as well as some other relevant data but I haven’t had any issue once I figured out the resolver and invoke functions. When the macro loads, it fetches the data, stores it locally then sends it to the calendar to load and up until this point, it’s worked wonderfully. However, these last 24 hours it’s been acting very weird and i’m at a complete loss as to what to do.

Basically, the storage API will just remove anything i have stored and return a blank array. This doesn’t happen all of the time, and it’s not always with all data. For example, sometimes my “teams” array will return blank but my events and work types will be okay. Other times, the “work types” will be blank but either way - it usually starts with one array going blank, then on the next refresh it’s all of them and despite my best efforts, I haven’t been able to figure out how that’s even possible.

I haven’t touched this functionality in my recent work on the app, so it’s difficult to look at anything i’ve personally done. I had a function that did delete items but i removed that a while ago and yet this bizarre behavior is still happening.

If anyone has any insights or would be willing to help me out i’d be forever appreciative, thank you very much for taking the time to read :slight_smile:

Hi @NathanHenderson!

Sorry to hear that you’re seeing some weird behaviour with the storage APIs.

Your description When the macro loads, it fetches the data, stores it locally then sends it to the calendar and This doesn’t happen all of the time, and it’s not always with all data smells like a possible race condition to me. Changes in latency or other environmental factors may have meant it might have started manifesting even without a code change. It’s a bit hard to tell without seeing the code, but is there a chance your code is writing the empty array to storage before its been initialised with the data that you’re fetching? Or could you have multiple users accessing the macro concurrently and overwriting each other’s data?

If you’re willing to share the code on the critical path for reading and writing to storage we might be able to provide more insight :slight_smile:

cheers,
Tim

2 Likes

Hi, thank you very much for your reply!

I’ve just done another combing through of my code and it turns out i’d accidentally set the state that checks whether or not the app as a whole has loaded to initialize as true instead of false which meant that, as you said, a race condition played out which meant that sometimes the local blank array that’s initialized for all of my objects would replace whatever I’d stored using storage API, right before trying to load in the data. Such a simple error that caused a lot of agony haha - but thank you very much once again for your help!

1 Like

You’re very welcome @NathanHenderson, glad to hear you got it sorted out :slight_smile: