diff options
author | zeripath <art27@cantab.net> | 2021-09-13 09:40:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-13 09:40:55 +0100 |
commit | 8af7a21085b73379e5f268c7a52ea77c51bb9246 (patch) | |
tree | 896996d6438805e43e0e3f4429e6322b5035fa99 /vendor | |
parent | 132c8c43e10d4953ecd091b4b8d7343344319839 (diff) | |
download | gitea-8af7a21085b73379e5f268c7a52ea77c51bb9246.tar.gz gitea-8af7a21085b73379e5f268c7a52ea77c51bb9246.zip |
Update go-chi/session (fixes "race" in tests) (#17031)
Update to latest go-chi/session where the NewManager causes a new
Provider instantiation instead of reconfiguring an old one.
(https://gitea.com/go-chi/session/pulls/1)
The NewManager call is now concurrency safe and would allow live
reconfiguration in future but for now this PR simply fixes an
intermittent "data-race" detected in our tests. (See
https://drone.gitea.io/go-gitea/gitea/43900/2/14)
Related #17027
Related #1441
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/gitea.com/go-chi/session/session.go | 31 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
2 files changed, 27 insertions, 6 deletions
diff --git a/vendor/gitea.com/go-chi/session/session.go b/vendor/gitea.com/go-chi/session/session.go index 475612ffb1..5c2afedc93 100644 --- a/vendor/gitea.com/go-chi/session/session.go +++ b/vendor/gitea.com/go-chi/session/session.go @@ -23,6 +23,7 @@ import ( "fmt" "net/http" "net/url" + "reflect" "time" ) @@ -291,17 +292,34 @@ type Provider interface { GC() } -var providers = make(map[string]Provider) +var providers = make(map[string]func() Provider) // Register registers a provider. func Register(name string, provider Provider) { - if provider == nil { + if reflect.TypeOf(provider).Kind() == reflect.Ptr { + // Pointer: + RegisterFn(name, func() Provider { + return reflect.New(reflect.ValueOf(provider).Elem().Type()).Interface().(Provider) + }) + return + } + + // Not a Pointer + RegisterFn(name, func() Provider { + return reflect.New(reflect.TypeOf(provider)).Elem().Interface().(Provider) + }) +} + +// RegisterFn registers a provider function. +func RegisterFn(name string, providerfn func() Provider) { + if providerfn == nil { panic("session: cannot register provider with nil value") } if _, dup := providers[name]; dup { panic(fmt.Errorf("session: cannot register provider '%s' twice", name)) } - providers[name] = provider + + providers[name] = providerfn } // _____ @@ -318,12 +336,15 @@ type Manager struct { } // NewManager creates and returns a new session manager by given provider name and configuration. -// It panics when given provider isn't registered. +// It returns an error when requested provider name isn't registered. func NewManager(name string, opt Options) (*Manager, error) { - p, ok := providers[name] + fn, ok := providers[name] if !ok { return nil, fmt.Errorf("session: unknown provider '%s'(forgotten import?)", name) } + + p := fn() + return &Manager{p, opt}, p.Init(opt.Maxlifetime, opt.ProviderConfig) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 67646b0b73..853286cdaa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -18,7 +18,7 @@ gitea.com/go-chi/cache/memcache # gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e ## explicit gitea.com/go-chi/captcha -# gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee +# gitea.com/go-chi/session v0.0.0-20210913064732-2ac132b0fa07 ## explicit gitea.com/go-chi/session gitea.com/go-chi/session/couchbase |