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

Fix accessing to layer without lock #1351

Merged
merged 1 commit into from Sep 27, 2022

Conversation

tyler92
Copy link
Contributor

@tyler92 tyler92 commented Sep 16, 2022

There was a possibility to panic due to such behavior: attempted to update last-writer in lockfile without the write lock

Fixes: #1324

Signed-off-by: Mikhail Khachayants tyler92@inbox.ru

@tyler92
Copy link
Contributor Author

tyler92 commented Sep 16, 2022

I really don't know how to make sure that there are no double locks.

@rhatdan
Copy link
Member

rhatdan commented Sep 16, 2022

When adding a lock, it is always worth while opening [WIP] PR with this Change in Podman and Buildah to have their tests run against them.

@tyler92
Copy link
Contributor Author

tyler92 commented Sep 16, 2022

Ok, I'll do it

layers.go Outdated
@@ -563,6 +563,8 @@ func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Dri
uidMap: copyIDMap(s.uidMap),
gidMap: copyIDMap(s.gidMap),
}
defer rlstore.Unlock()
rlstore.RLock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC these should be write locks, so that incomplete layers can be cleaned up. (Not in the newROLayerStore case)

warning: I didn’t actually review this carefully — this is just a drive-by comment to make sure it is not forgotten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed. FYI: I'm still trying to check it with Podman and Buildah CI.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The crash in #1324 only happens on recovery from a previous crash, so I’m not at all sure those CI systems exercise that case. If they did, we should have found #1324 much earlier.

Copy link
Contributor Author

@tyler92 tyler92 Sep 21, 2022

Choose a reason for hiding this comment

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

Yes, I understand. I just want to make sure, that my change doesn't broke something (e.g. there is no double lock).

When adding a lock, it is always worth while opening [WIP] PR with this Change in Podman and Buildah to have their tests run against them.

layers.go Show resolved Hide resolved
There was a possibility to panic due to such behavior:
attempted to update last-writer in lockfile without the write lock

Fixes: containers#1324

Signed-off-by: Mikhail Khachayants <tyler92@inbox.ru>
@tyler92
Copy link
Contributor Author

tyler92 commented Sep 21, 2022

CI in Podman and Buildah is green. @mtrmac what do you think about this PR?

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

This LGTM.

For consistency, could you please update containers.go and images.go to do it the same way? They are correct now AFAICS, it’s just a matter of looking the same if they are doing the same thing:

  • Lock the lock after creating the whole store object, not before
  • Use the store’s Lock/RLock/Unlock method, instead of directly manipulating a lockfile object.

@rhatdan rhatdan merged commit d9e14ec into containers:main Sep 27, 2022
rhatdan added a commit to rhatdan/storage that referenced this pull request Sep 27, 2022
Match containers and image lock to the new layer lock method.
in containers#1351

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/storage that referenced this pull request Sep 28, 2022
Match containers and image lock to the new layer lock method.
in containers#1351

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
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

Successfully merging this pull request may close these issues.

Panic: attempted to update last-writer in lockfile without the write lock
3 participants