-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: Implementing a limitation for the open() #2314
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nicely done 👏 !
I have left some nitpick comments, but mostly I want the message fixed ... possibly when the file is missing as well :).
I have tested it and it seems to work great with archives as well ;)
Thanks, @mstoykov 🙇 Addressed all comments 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏 I have 2 more comments with notes, but I wouldn't argue you should work on them now especially if the plan is to move to io/fs in the next release, which will in practice redo all of this either way.
js/initcontext.go
Outdated
defer func() { | ||
if errors.Is(err, fsext.ErrPathNeverRequestedBefore) { | ||
// loading different files per VU is not supported, so all files should are going | ||
// to be used inside the scenario should be opened during the init step (without any conditions) | ||
err = fmt.Errorf( | ||
"open() can't be used under with files that weren't opened during initialization (__VU==0), path: %q", | ||
filename, | ||
) | ||
} | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note(not actionable): Technically, this error will either happen on afero.IsDir
or not at all. But it seems kind of strange to check it only there and also when/if we ever stop checking that as we move to io/fs it will be a bit confusing why it wasn't previously checked.
I am noting this for future reference only, don't do anything about it just based on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 not sure if I get it. The error happens afero.IsDir
and afero.ReadFile
. Even if we move to the io/fs
still should happen on the equivalent of the afero.ReadFile
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we move – yes, but when we move to io/fs, afero.IsDir
will hopefully be just dropped ;).
What I am trying to say is that if afero.IsDir
did not return fsext.ErrPathNeverRequestedBefore
than afero.Readfile
will not return it either ... or we have bugs I guess or some strange race condition.
I wondered for a bit if we can't just add afero.IsDir
check in the already reimplemented Open
, but I am not certain we always use the CacheOnReadFs and IIRC we don't so 🤷
js/initcontext.go
Outdated
fs := i.filesystems["file"] | ||
|
||
alreadyOpenedFS, ok := fs.(fsext.OnlyOpenedEnabler) | ||
if !ok { | ||
return | ||
} | ||
|
||
alreadyOpenedFS.AllowOnlyOpened() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note(not actionable): This seems a bit fragile, as we can at any point change what the top fs for file
is and then this suddenly won't work. This is unlikely as this code is very rarely changed and will probably be spotted.
The test below also doesn't test with loader.CreateFilesystems
which is what is used in reality. An integration test with it might be better, but I see no test actually has ever used it so 🤷 maybe there are some problems I can't remember at the moment. Either way this is fine for now, hopefully we will be moving to io/fs soon and that will lead to some bigger changes and hopefully more tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall 👍 but I have a renaming request and some smaller cleanup remarks.
One more thing. To improve test coverage it might also make sense to add tests for successful cases (i.e. with if (__VU==0)
and with absent if
condition)?
fe37712
to
aeb4217
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the renaming! LGTM 👍
Implementing a limitation for the open() that limits opening files by the list of the files that were opened during the initialization step (__VU == 0). For example, a code like: ```js if (__VU >0) { JSON.parse(open("./arr.json")); } ``` Should return an error. Closes #1771
Co-authored-by: Mihail Stoykov <MStoykov@users.noreply.github.com>
aeb4217
to
58792b3
Compare
Implementing a limitation for the open() that limits opening files
by the list of the files that were opened during the initialization
step (__VU == 0).
For example, a code like:
Should return an error.
Closes #1771