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

Data race in FetchSignaturesForReference #2277

Closed
RTann opened this issue Sep 23, 2022 · 1 comment · Fixed by #2283
Closed

Data race in FetchSignaturesForReference #2277

RTann opened this issue Sep 23, 2022 · 1 comment · Fixed by #2283
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@RTann
Copy link
Contributor

RTann commented Sep 23, 2022

Description

For each fetched signature, a new goroutine is spawned here. Each of these goroutines use the same err error variable, originally declared here.

To make it a bit easier to read, I will copy and paste the code below:

g.Go(func() error {
	signatures[i].Payload, err = sig.Payload()
	if err != nil {
		return err
	}
	signatures[i].Base64Signature, err = sig.Base64Signature()
	if err != nil {
		return err
	}
	signatures[i].Cert, err = sig.Cert()
	if err != nil {
		return err
	}
	signatures[i].Chain, err = sig.Chain()
	if err != nil {
		return err
	}
	signatures[i].Bundle, err = sig.Bundle()
	return err
})

We can see that we always use the same err in each goroutine, as = is used. This can lead to a race condition where errors are never propagated. For example, say we have two signatures, so two goroutines. It is possible that something like signatures[i].Payload, err = sig.Payload() is called and returns an error for one goroutine, but before it checks if err != nil, we context switch to the other goroutine which gives us err = nil in signatures[i].Payload, err = sig.Payload(). Then, we will never catch the error in either goroutine.

Version

I am using v1.12.1, but from what I can tell, this has been around since this PR, which has been around since v1.2.1.

@RTann RTann added the bug Something isn't working label Sep 23, 2022
@znewman01 znewman01 added the good first issue Good for newcomers label Sep 26, 2022
@RTann
Copy link
Contributor Author

RTann commented Sep 26, 2022

#2283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants