There have been a few challenges involved with making sure Passive and Active Service Discovery modules are writing to a common JSON file (datastore) and are keeping the data current.
There were initial hiccups. Both modules kept overwriting each other’s data after every phase as the writing mode was ‘w’.
Then, later I changed it to append, and that worked fine. But, the problem with this approach was that there would be stale data which may or may not be correct at a later stage of time.
Hence, I choose a different approach entirely. After the initial file was created, every time either of the modules had to write data to it, then they first needed to read the entire datastore JSON file first. Then, verified about the credibility of the data present, check if the data to be written has not already been written. Then, if both the conditions are met, whatever the module writes can be considered current and latest.