Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

file_system: group promisify, avoid relying on in-advance fs.exists checks #112

Merged
merged 5 commits into from
Jul 12, 2018

Conversation

ChALkeR
Copy link
Contributor

@ChALkeR ChALkeR commented Jun 29, 2018

Again several commits here with their own descriptions.

This removes fs.exists usage and does some minor cleanup.
My intention was to remove the in-advance checks that might result in a race.


This change is Reviewable

@ChALkeR ChALkeR force-pushed the fix-fs-race branch 3 times, most recently from 631687c to aa11bfe Compare June 30, 2018 00:00
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Jun 30, 2018

Travis failure in https://travis-ci.org/tensorflow/tfjs-node/jobs/398469237 looks unrelated (seed 40947).

@ChALkeR ChALkeR force-pushed the fix-fs-race branch 3 times, most recently from 46c846a to 806442d Compare June 30, 2018 10:48
@nkreeger
Copy link
Contributor

:lgtm_strong: One small comment - thanks again!


Review status: :shipit: complete! 1 of 1 LGTMs obtained


src/io/file_system.ts, line 31 at r1 (raw file):

notExist

Let's call this doesNotExistHandler.


Comments from Reviewable

ChALkeR added 3 commits July 1, 2018 03:11
No need to call promisify() per every method call,
we can do that once instead and save the result.
This avoids possible race conditions, e.g. when more than one
parallel async .save() operation is called (from a single or several
processes) sharing a common prefix which does not yet exist.

Instead, createOrVerifyDirectory() now just tries creating the dir,
and if that fails -- checks _why_ that failed, if it is anything
other than the directory already existing -- throws an error, if
it's the dir already existing -- skips that and continues.

Refs: https://nodejs.org/api/fs.html#fs_fs_exists_path_callback
Instead, use fs.stat and fs.readFile directly and let them throw if
the file in question does not exist, and format the error in a way
how we want using a small helper function.
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Jul 1, 2018

@nkreeger Updated. That added one line though ;-).

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Jul 1, 2018

Ah, also, it was Path ${path} does not exist: loading failed., but Weight file ${path} does not exist: loading failed, note the dot absense.

This PR changes that to a common variant (without the dot). Tests are happy both ways.
I can re-add it back if you want :-). To both variants, that is.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@nkreeger
Copy link
Contributor

nkreeger commented Jul 2, 2018

Review status: :shipit: complete! 1 of 1 LGTMs obtained


src/io/file_system.ts, line 121 at r2 (raw file):

Path

I can see this getting confusing on the command line - do we need a name? If so, maybe something like 'Path from load' or 'loading model'.


src/io/file_system.ts, line 139 at r2 (raw file):

'Weight file'

Ditto here.


Comments from Reviewable

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Jul 4, 2018

@nkreeger I am not sure that I understood.
This PR did not change those two error messages except for the dot at the end.

Current ones in this PR are: Path ${x} does not exist: loading failed and Weight file ${y} does not exist: loading failed, where x and y are paths without quotes.

Did you mean that it's unclear that the error comes from loading a model, and there should be s/loading/loading model/ in those two error messages? If so, it will also change test expectatons (which is probably fine at this point).

I did not understand Path from load variant, it would look like Path from load ${x} does not exist: loading failed which doesn't look better to me. I am not a native English speaker, though.

@nkreeger nkreeger merged commit 16752ca into tensorflow:master Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants