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

Do not expect app.getPath('userData') to be there before app.once('ready') #19662

Closed
bpasero opened this issue Feb 1, 2017 · 13 comments
Closed
Assignees
Labels
*as-designed Described behavior is as designed
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Feb 1, 2017

There is a discussion going on in 08a1700 where @chrmarti saw an issue on startup for new users that never started Code before. I never saw this issue but the fix seems odd to me: we now suddenly create the directory (userData) via mkdirp that is owned by Electron/Chrome, which seems wrong. It should be created by the framework, not us.

Can we move the getNodeCachedDataDir() into the app.once('ready') callback? That is the place where all code should go that assumes a certain directory structure to be present, not before.

@jrieken
Copy link
Member

jrieken commented Feb 1, 2017

The idea is to run in parallel to the ready-event because if often takes a long time to be ready. @bpasero What is the issue here and what do you mean but is 'owned by Electron'? We are not locking or deleting the directory, just create it if its not there.

@jrieken jrieken added info-needed Issue requires more information from poster and removed important Issue identified as high-priority labels Feb 1, 2017
@bpasero
Copy link
Member Author

bpasero commented Feb 1, 2017

This is how it used to be:

var dir = path.join(app.getPath('userData'), 'CachedData');
mkdir(dir);

Which is totally fine because we create the CachedData directory and we own it.

This is how @chrmarti changed it:

var dir = path.join(app.getPath('userData'), 'CachedData');
mkdirp(dir); // note this mkdirP

Which imho is not ok because we start to create directories all the way down until root if not existing (e.g. /Users/bpasero/Library/Application Support/code-oss-dev). We would do so in parallel with Electron/Chromium, because according to electron/electron#5340 the directory will be there inside the app.on('ready').

As such, we should move code into app.on('ready') that assumes certain Electron directories to be there.

@chrmarti
Copy link
Contributor

chrmarti commented Feb 1, 2017

To clarify why the change was done: Before when running with a new user data dir that did not exist yet, mkdir would fail because the parent folder (the user data dir) did not exist. As a result of that no window opened, that reproduced reliably on my machine when using --user-data-dir or moving my regular user data dir to a backup location. (bug #19529)

@bpasero
Copy link
Member Author

bpasero commented Feb 1, 2017

@chrmarti so does it reproduce if you move that code into app.on(ready)?

@chrmarti
Copy link
Contributor

chrmarti commented Feb 1, 2017

No, it no longer reproduces.

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Feb 1, 2017
@jrieken
Copy link
Member

jrieken commented Feb 2, 2017

My motivation to move things before the ready-event is performance. It takes often takes 100-200ms before that event fires (avg. 293ms, 60th percentile 135ms). Our JS code doesn't do anything in that time because the event is generated outside the JS event loop (in native code). Today most (expensive) things like starting the shared process, loading files (backup, config, storage) happen after the ready-event resulting in a classic waterfall runtime behaviour. I didn't want to contribute to that waterfall by moving the cached data check after the ready-event but by letting it run in parallel. Also, I think we should move the afore mentioned things off the waterfall sequence and let them run in parallel.

@bpasero Is this just about us creating a folder that otherwise electron would create or about doing stuff before the ready-event? What problem do you see in us creating that folder and then electron not or vice versa?

Again, there are low hanging performance improvements and more code should be moved before the ready-event. Wrt operations that read files we can also not do them; there is no backup to read without a folder, byte code caching happens only on the second start etc...

Alternatively, we could refrain from creating the full path but only create the root dir if missing (code-oss-dev). That would likely help us with permission issues on non-standard paths and make us not walk up to root.

@bpasero
Copy link
Member Author

bpasero commented Feb 2, 2017

I see the motivation. +1 for creating the root directory but not all the directories going up.

@chrmarti
Copy link
Contributor

chrmarti commented Feb 2, 2017

We decided to walk up the parent folders because there could be scenarios where users use --user-data-dir to point to a folder that needs its parent folder(s) created first.

@bpasero bpasero closed this as completed Feb 2, 2017
@bpasero bpasero added *as-designed Described behavior is as designed and removed bug Issue identified by VS Code Team member as probable bug labels Feb 2, 2017
@jrieken
Copy link
Member

jrieken commented Feb 2, 2017

There is still a problem when mkdirp fails because of some unknown reason (permission?) in that case we found start up. I'll push a fix for that

@jrieken jrieken reopened this Feb 2, 2017
@jrieken jrieken added this to the February 2017 milestone Feb 2, 2017
@jrieken jrieken closed this as completed Feb 2, 2017
@chrmarti
Copy link
Contributor

chrmarti commented Feb 2, 2017

Thought I had that covered. It should fail and print the associated error to the console.

@chrmarti
Copy link
Contributor

chrmarti commented Feb 2, 2017

@jrieken Just see your change now. I would definitely print the error to the console, otherwise any such problem will be very hard to track down.

We didn't know where the problem originated from and started with a binary search through our insiders builds to narrow down the change sets that could have caused the original problem. Then continued by looking at the diff stat and then diff between the two insider builds where it broke. Please log :)

@jrieken
Copy link
Member

jrieken commented Feb 2, 2017

otherwise any such problem will be very hard to track down.

I generally agree but in this case it's not a problem. See, it's just an optional directory we pass on to the loader such that it can cache byte code. If that's missing everything should still work and startup can continue, it's just a little slower.

Once we move more and vital things here we should handle the error properly. Now I'd rely on electron doing that

@chrmarti
Copy link
Contributor

chrmarti commented Feb 2, 2017

I see, good for me then.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed
Projects
None yet
Development

No branches or pull requests

3 participants