move some inits calling conf.Watch to explicit Inits (#52521)

As part of my work, I need to be able to do some longer-running
processing before the config server etc can be initialized. This gets
interrupted by conf deadlock detection caused by `conf.Watch` being
started in `init` functions.
By moving them to explicitly called `Init` functions, we can control
when this begins, so that it can happen _after_ the longer-running
processing has completed and before it is needed.

## Test plan

This is where I need _your_ help. What way can this be tested, besides
"startup and assuming it looks right?"
This commit is contained in:
Noah S-C 2023-06-01 15:32:04 +01:00 committed by GitHub
parent c116bb593e
commit 7b33beb48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 2 deletions

View File

@ -34,6 +34,7 @@ go_library(
"//internal/adminanalytics",
"//internal/api",
"//internal/auth",
"//internal/auth/userpasswd",
"//internal/conf",
"//internal/conf/conftypes",
"//internal/conf/deploy",

View File

@ -23,10 +23,12 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app/ui"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app/updatecheck"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/bg"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/highlight"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/httpapi"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/siteid"
oce "github.com/sourcegraph/sourcegraph/cmd/frontend/oneclickexport"
"github.com/sourcegraph/sourcegraph/internal/adminanalytics"
"github.com/sourcegraph/sourcegraph/internal/auth/userpasswd"
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
@ -110,6 +112,9 @@ func Main(ctx context.Context, observationCtx *observation.Context, ready servic
}
}
userpasswd.Init()
highlight.Init()
// After our DB, redis is our next most important datastore
if err := redispoolRegisterDB(db); err != nil {
return errors.Wrap(err, "failed to register postgres backed redis")

View File

@ -94,6 +94,7 @@ var highlightConfig = syntaxHighlightConfig{
Extensions: map[string]string{},
Patterns: []languagePattern{},
}
var baseHighlightConfig = syntaxHighlightConfig{
Extensions: map[string]string{
"jsx": "jsx", // default `getLanguage()` helper doesn't handle JSX
@ -136,7 +137,7 @@ var baseEngineConfig = syntaxEngineConfig{
},
}
func init() {
func Init() {
// Validation only: Do NOT set any values in the configuration in this function.
conf.ContributeValidator(func(c conftypes.SiteConfigQuerier) (problems conf.Problems) {
highlights := c.SiteConfig().SyntaxHighlighting

View File

@ -28,6 +28,7 @@ go_library(
"//enterprise/internal/authz/subrepoperms",
"//enterprise/internal/database",
"//enterprise/internal/oobmigration/migrations",
"//internal/auth/userpasswd",
"//internal/authz",
"//internal/conf",
"//internal/database",

View File

@ -5,6 +5,7 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/worker/shared"
"github.com/sourcegraph/sourcegraph/enterprise/internal/oobmigration/migrations"
"github.com/sourcegraph/sourcegraph/internal/auth/userpasswd"
"github.com/sourcegraph/sourcegraph/internal/debugserver"
"github.com/sourcegraph/sourcegraph/internal/env"
"github.com/sourcegraph/sourcegraph/internal/observation"
@ -22,6 +23,10 @@ func (svc) Configure() (env.Config, []debugserver.Endpoint) {
func (svc) Start(ctx context.Context, observationCtx *observation.Context, ready service.ReadyFunc, config env.Config) error {
go setAuthzProviders(ctx, observationCtx)
// internal/auth/providers.{GetProviderByConfigID,GetProviderbyServiceType} are potentially in the call-graph in worker,
// so we init the built-in auth provider just in case.
userpasswd.Init()
return shared.Start(ctx, observationCtx, ready, config.(*shared.Config), getEnterpriseInit(observationCtx.Logger))
}

View File

@ -6,7 +6,7 @@ import (
)
// Watch for configuration changes related to the builtin auth provider.
func init() {
func Init() {
go func() {
conf.Watch(func() {
newPC, _ := GetProviderConfig()