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

Don't open a new file descriptor for a locked state. #17636

Merged
merged 3 commits into from
Mar 19, 2018

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Mar 19, 2018

Only open a new file descriptor for RefreshState if we haven't written a
state, and don't have the correct state open already. This prevents
windows from failing to refresh a locked state.

This also surfaces initial state read errors, which were previously assumed to be because of an empty state. On windows, this could mask the error return when file access is denied.

Fixes #17620

Refreshing a locked state on windows could return nil if the read path
was locked, no state was yet written, and the read path is the same as
the write path.

Add a test that locks then refreshes a newly initialized state struct.
ReadState would hide any errors, assuming that it was an empty state.
This can mask errors on Windows, where the OS enforces read locks on the
state file.
Only open a new file descriptor for RefreshState if we haven't written a
state, and don't have the correct state open already. This prevents
windows from failing to refresh a locked state.
// the error is either io.EOF or "invalid argument", and both are from
// an empty state.
return nil, ErrNoState
if err == io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed comment here talks about both io.EOF and "invalid argument". Is the "invalid argument" case taken care of by the nil check above, or taken care of some other way here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, "invalid argument" is only expected when we have a nil *os.File. At one point that was ok to use for ReadState to indicate the absence of state. I'd like to not have that at all, but that takes some more serious auditing to make sure we don't have any more code paths passing it in.

@jbardin
Copy link
Member Author

jbardin commented Mar 19, 2018

FTR, All state tests passing when run directly on a Windows host.

@jbardin jbardin merged commit 6b6b92f into master Mar 19, 2018
@jbardin jbardin deleted the jbardin/windows-refresh-lock branch March 19, 2018 23:17
@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v0.11.4 plans resource creation where resources already exist and are listed in tfstate.
2 participants