Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how appData/userData folder behaves with multiple Electron instances #4727

Closed
bpasero opened this issue Mar 9, 2016 · 10 comments
Closed

Comments

@bpasero
Copy link
Contributor

bpasero commented Mar 9, 2016

This is more a question or ask to update docs, not an issue: When using Electron, all of Chromes configuration files end up in appData (e.g. local storage, indexdb). It is not clear to me if it is OK to have 2 instances of Electron running at the same time both sharing the same appData folder.

In the past I have seen at least one case where this was not possible: Using IndexDB seems to lock the appData folder so that a second instance is not fighting over the IndexDB resources. This seems like a valid thing for IndexDB to do.

However, in which cases is it OK to have multiple instances on the same appData folder and when should it be prevented? Imagine the second instance is not spawning a renderer process and is just there to talk to the "main" instance via some ipc mechanism. Would the appData folder still have resources that both instances would fight over?

@zcbenz
Copy link
Member

zcbenz commented Mar 10, 2016

Chromium doesn't have good support for running two instances at the same time, most resources are guarded with file locks, like localStorage, so if you are using localStorage in one instance the accesses in other instances will be refused. And for resources that are not guarded by locks, race conditions might happen and it would be very bad.

@zcbenz zcbenz closed this as completed Mar 10, 2016
@bpasero
Copy link
Contributor Author

bpasero commented Mar 10, 2016

@zcbenz but would you say that the appData folder is mainly used for renderers and that it is somewhat safe to have 2 instances of the main process running at the same time as long as they dont both open windows?

@zcbenz
Copy link
Member

zcbenz commented Mar 10, 2016

Yeah under that condition it should be OK.

@bpasero
Copy link
Contributor Author

bpasero commented Mar 14, 2016

@zcbenz another question: do you think it is possible to migrate the app data folder to another location? I am wondering at which time Electron/Chromium expects the app data folder to be there, e.g. is there a way to do this operation (even if it takes 1 second) before this folder is needed?

@bpasero
Copy link
Contributor Author

bpasero commented Mar 14, 2016

@zcbenz actually I did a small experiment and it seems to me that the appdata folder is empty as long as no window is opened, after that, I see the following folders created: GPUCache, Local Storage. So I would assume I could do the migration before any window opens.

@bpasero
Copy link
Contributor Author

bpasero commented Mar 14, 2016

The other question is if these folders are fit to be moved to another location or not...

@zcbenz
Copy link
Member

zcbenz commented Mar 14, 2016

@bpasero As long as you call app.setPath very early it would be safe to set the userData folder to anywhere you want, and copying original app data to the new location should be OK. But there is a bug that the userData folder is created before running user's main process script (#2668), so after migration the old userData folder will still be there.

@bpasero
Copy link
Contributor Author

bpasero commented Mar 14, 2016

Allright, thanks for the pointer to the other issue.

@TimNZ
Copy link

TimNZ commented Jul 3, 2016

Ok so if I am spawning multiple instances of Electron via multiple simultaneous instances of a Node script that runs Nightmare, then this may explain why the scripts don't execute properly?

E.g.
Master node process (persistent)
-> Spawns runner.js via node-worker-farm module -> new Node process
----> runner.js fires up Nightmare script

Works fine with one spawned process, more than one and Nightmare renderer actions don't work reliably.

@TimNZ
Copy link

TimNZ commented Jul 3, 2016

@zcbenz It seems #2668 was solved so using app.setPath and creating diff appData and userData for each instance would solve the conflicts for multiple instances i.e. I presume that is what happens now each for Electron app with a different package name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants