electron: Multipe instances of an Electron app have problems with localStorage

If we start multipe instances of an Electron app, they will have problems with localStorage:

  • One instance can not see the change to the localStorage made by another one during its lifetime.
  • storage event is not fired after another instance made change to the localStorage.
  • If two instances make changes to a same key, the last change win (becomes persistent) after all of them exit.

I think this problem, as well as #2483, make multipe instance mode of electron very dangerous. I think Electron should officially ban multipe instance mode untils these problems are solved, or users’ data are in risk.

Tested with 0.30.4-win32 on Win7 64bit.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Would IndexedDB will suffer from the same issue?

the situation is two independent browser context operating on same storage partition path, these race conditions are to happen. You need to set a different user data path for the new instance.

One possible way to overcome this (while a real solution is being worked on), is to modify your app in the following manner: When the application loads, it checks if there’s another instance. If there isn’t it loads the business logic. If there is, it will notify the other instance and exit. The other instance will open a new window for your app so it will appear like you have 2 instances running. The underline assumption here is that the issue doesn’t happen in 2 windows generated from the same main process. This way you should be able to bypass the persistency issues, but it will complicate the main process.

Regarding the following:

If two instances make changes to a same key, the last change win (becomes persistent) after all of them exit.

The fact that that the change is written when they exit, is a problem. But the last change wins, isn’t (that’s exactly how localStorage is designed to work).