atom / telemetry

sends usage metrics to GitHub's internal analytics pipeline
MIT License
11 stars 12 forks source link

Fallback to not store events whenever the IndexedDB database is not available #31

Closed rafeca closed 5 years ago

rafeca commented 5 years ago

Context

We've just realized that Electron locks the IndexedDB database when it's opened, so multiple processes cannot access it concurrently (which makes a lot of sense 😅). This causes issues when using multiple versions of Atom at the same time, since the Electron folder (which is where the IndexedDB files are stored) is common between versions.

When this happens, IndexedDB.open() throws an error, which we're currently not handling so it appears on the development console (the exception actually appears each time an event is logged, since we're awaiting the resulting promise from IndexedDB.open() for each event).

Solution

This PR consists of two commits:

  1. The first one takes care of handling the IndexedDB exceptions and converting all the methods to store/retrieve metrics into noops, so no more exceptions are shown in console.
  2. The second commit goes a step further, and takes advantage of the new generic way of creating stores for telemetry to create an in-memory storage class that is used as a fallback whenever the IndexedDB database is not available.

Thanks to this, if for some reason we can't operate with the IndexedDb, metrics will still get generated and reported (but not persisted between sessions).