-
Notifications
You must be signed in to change notification settings - Fork 173
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 STM error when fetching a container needs multiple different tokens #1370
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
csasarak
changed the title
Registryctx stm fix
Fix STM error when fetching a container needs multiple different tokens
Jan 26, 2024
meghfossa
approved these changes
Jan 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
I was investigating STM errors and found one in the way that we were handling auth tokens with STM. The idea is that for container scanning we want to share an auth token between a few workers. However, this code originally used
putTMVar
for updating the variable holding the token. For registries that use only one token this is fine, theRegistryCtx
starts empty, is filled, and then that token works for every layer archive download. In the case of some registries the token for downloading blobs may be different than the one for fetching the manifest.When that happens:
RegistryCtx
usingputTMVar
so other threads can use it.putTMVar
will wait for theRegistryCtx
TMVar
to be emptied (using some variation oftakeTMVar
) which will never happen.TMVar
to change, but also notices that there isn't an unblocked thread with a reference to theTMVar
. Realizing that theTMVar
will never be released, it kills all the blocked threads with athread blocked indefinitely in an STM transaction
exception.This PR:
writeTMVar
but also adds some logic so that when one thread is working to get a new auth token, the other ones will wait for it.Acceptance criteria
Testing plan
A simple interactive test involves using our currently released fossa to get the alpine image from AWS's public registry:
It should fail with an STM exception.
Running the same command with the code on this branch should succeed. If you run it with
--debug
, you can also observe the coordination of threads fetching tokens in the debug bundle:Risks
The thread that's fetching the token could receive a malformed challenge and fail, leaving the
RegistryCtx
in a bad state that would result in the same STM error as before.This PR still represents an improvement in the number of cases where that could happen so I still think it's worth merging. I'd like to see if there's a more general way to handle situations like that as part of continuing work on ANE-883.
Metrics
References
Checklist
docs/
.docs/README.ms
and gave consideration to how discoverable or not my documentation is.Changelog.md
. If this PR did not mark a release, I added my changes into an# Unreleased
section at the top..fossa.yml
orfossa-deps.{json.yml}
, I updateddocs/references/files/*.schema.json
AND I have updated example files used byfossa init
command. You may also need to update these if you have added/removed new dependency type (e.g.pip
) or analysis target type (e.g.poetry
).docs/references/subcommands/<subcommand>.md
.