Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(coderd/coderdtest/oidctest): protect mutable fields with rwmutex#17151

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 6 commits intomainfromcj/flake/TestOIDCDomainErrorMessage
Apr 2, 2025

Conversation

@johnstcn
Copy link
Member

Fixes a test flake seen here:https://github.com/coder/coder/actions/runs/14129446248/job/39585915325

WARNING: DATA RACEWrite at 0x00c0174f5918 by goroutine 11046:  github.com/coder/coder/v2/coderd/coderdtest/oidctest.(*FakeIDP).SetRedirect()      /home/runner/work/coder/coder/coderd/coderdtest/oidctest/idp.go:1280 +0x1e6  github.com/coder/coder/v2/coderd/coderdtest/oidctest.(*FakeIDP).LoginWithClient()      /home/runner/work/coder/coder/coderd/coderdtest/oidctest/idp.go:494 +0x170  github.com/coder/coder/v2/coderd/coderdtest/oidctest.(*FakeIDP).AttemptLogin()      /home/runner/work/coder/coder/coderd/coderdtest/oidctest/idp.go:[479](https://github.com/coder/coder/actions/runs/14129446248/job/39585915325#step:7:480) +0x624  github.com/coder/coder/v2/coderd_test.TestOIDCDomainErrorMessage.func2()      /home/runner/work/coder/coder/coderd/userauth_test.go:2014 +0x1f2  testing.tRunner()      /opt/hostedtoolcache/go/1.24.1/x64/src/testing/testing.go:1792 +0x225  testing.(*T).Run.gowrap1()      /opt/hostedtoolcache/go/1.24.1/x64/src/testing/testing.go:1851 +0x44Previous read at 0x00c0174f5918 by goroutine 104380:  golang.org/x/oauth2.(*Config).Exchange()      /home/runner/go/pkg/mod/golang.org/x/oauth2@v0.28.0/oauth2.go:228 +0x1d8  github.com/coder/coder/v2/coderd.(*OIDCConfig).Exchange()      <autogenerated>:1 +0xb7  github.com/coder/coder/v2/coderd.New.func11.12.1.2.ExtractOAuth2.1.1()      /home/runner/work/coder/coder/coderd/httpmw/oauth2.go:168 +0x7b5  net/http.HandlerFunc.ServeHTTP()      /opt/hostedtoolcache/go/1.24.1/x64/src/net/http/server.go:2294 +0x47  github.com/go-chi/chi/v5.(*Mux).ServeHTTP()      /home/runner/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:73 +0x6f6  github.com/go-chi/chi/v5.(*Mux).Mount.func1()      /home/runner/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:327 +0x4bd  net/http.HandlerFunc.ServeHTTP()      /opt/hostedtoolcache/go/1.24.1/x64/src/net/http/server.go:2294 +0x47[...]

@johnstcnjohnstcn self-assigned thisMar 28, 2025
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@johnstcn
Copy link
MemberAuthor

OK, I changed this arounda little bit a lot. I'm now protecting alot more stuff inside a separate struct.

hookMutateTokenfunc(tokenmap[string]interface{})
fakeCoderdfunc(req*http.Request) (*http.Response,error)
hookOnRefreshfunc(emailstring)error
//fakeCoderd func(req *http.Request) (*http.Response, error)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

moved to protected

Suggested change
// fakeCoderd func(req *http.Request) (*http.Response, error)

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

A few caveats, but probably don't need to re-review.

providerProviderJSON
handler http.Handler
cfg*oauth2.Config
protfakeIDPProtected
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Maybe rename to priv/private, internal, etc? Prot makes me think of protoc/prototypes.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Renamed tolocked. 👍

ifcfg==nil {
cfg=&oauth2.Config{}
}
fn(cfg)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This mutates the config which is a pointer, meaning the mutex only protectsf.cfg but not the actual&oauth2.Config{} which could be modified and read in a racy way? I'd suggest at least making a copy of it, but did not verify if that's sufficient.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

If we take your suggestion above then we can just mutatef.cfg directly.

Copy link
Member

@mafredrimafredriApr 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

If we're worried about races and re-entrant locking, couldn't we just do this?

f.mu.Lock()iff.cfg==nil {f.cfg=&oauth2.Config{}}cfg:=*f.cfgf.mu.Unlock()fn(cfg)f.mu.Lock()f.cfg=&cfgf.mu.Unlock()

Copy link
MemberAuthor

@johnstcnjohnstcnApr 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

When I make a shallow copy off.cfg it causesTestOIDCSkipIssuer to fail, most likely due to some missing unexported fields. We may sadly have to live with the possibility of re-entrant locks.

@johnstcnjohnstcn merged commit8cecc4f intomainApr 2, 2025
28 of 29 checks passed
@johnstcnjohnstcn deleted the cj/flake/TestOIDCDomainErrorMessage branchApril 2, 2025 12:36
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsApr 2, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@mafredrimafredrimafredri approved these changes

@EmyrkEmyrkAwaiting requested review from Emyrk

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@johnstcn@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp