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

ino reuse in newInodeWithID #1594

Open
iain-macdonald opened this issue Mar 5, 2024 · 2 comments · May be fixed by #1599
Open

ino reuse in newInodeWithID #1594

iain-macdonald opened this issue Mar 5, 2024 · 2 comments · May be fixed by #1599

Comments

@iain-macdonald
Copy link
Contributor

At BuildBuddy, we run a modified version of the soci-snapshotter with the store/ directory from stargz-snapshotter patched in to support podman as described here. We recently encountered a bug caused by podman pulling two images in parallel in very quick succession (<1ms). I tracked it down to apparent ino reuse, hitting this error (note: the error message is incorrect, it should say refnode instead of rootnode, I can send a fix for this). Upon digging deeper, I discovered that the logic in idMap which attempts to reuse inos sometimes offers recently claimed inos for reuse. This is because the check for whether an inode is active calls Inode.Forgotten() which returns true for newly created, unused, non-persistent inodes (because lookupcount is 0 and parents is empty).

Practically, this means that if an refnode Inode has been created but not yet returned to the caller, and a second refnode.Lookup call attempts to mint a new ino, then the code will return the same ino for both of those Inodes (because the first one is releasable()), causing the fuse operations for the first Inode to route incorrectly, causing errors in stargz-snapshotter. You can tickle this bug by adding a time.Sleep() in newInodeWithID between when the Inode is created and when it is returned, and then getting that code to run twice in parallel by e.g. pulling images externally.

I think a reasonable fix is to only attempt to reuse inos after max loops all the way around, which should create a pretty big buffer time between when inos are initially allocated and when the snapshotter attempts to reuse them. In most cases I suspect that would prevent ino reuse, but maybe there are some cases where we're loop through all 4B inos. I'm open to other suggestions as well. Let me know what you think.

@iain-macdonald
Copy link
Contributor Author

Here's a branch illustrating the fix I proposed above: https://github.com/iain-macdonald/stargz-snapshotter/tree/inoreuse Though after thinking about it a little bit I realized this sort of leaks entries in the id map, as they won't be cleaned up anywhere near as frequently as currently (usually never). A slightly different approach that reuses inos more aggressively but will be far less likely to hit this bug would be to maintain some cap (initially say 10,000) and don't reuse inos as long as there are fewer then that cap. After hitting the cap, attempt to release inos from the first half of the map (to avoid the more recently allocated, second half), and increase the cap if the map truly fills up, freeing more id space for allocation. Obviously there are some more details to work out, but maybe that's a bit more palatable.

Let me know if you have thoughts here, Kohei. I can go ahead and address this in our forked version, but figured it'd be better to attempt an upstream fix if possible.

@ktock
Copy link
Member

ktock commented Mar 11, 2024

Thanks for reporting this. I'm trying to fix this in #1599 .

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 a pull request may close this issue.

2 participants