Browse Source

fix: Admin UI user creation fails before filer discovery (#7624) (#7625)

* fix: Admin UI user creation fails before filer discovery (#7624)

The credential manager's filer address function was not configured quickly
enough after admin server startup, causing 'filer address function not
configured' errors when users tried to create users immediately.

Changes:
- Use exponential backoff (200ms -> 5s) instead of fixed 5s polling for
  faster filer discovery on startup
- Improve error messages to be more user-friendly and actionable

Fixes #7624

* Add more debug logging to help diagnose filer discovery issues

* fix: Use dynamic filer address function to eliminate race condition

Instead of using a goroutine to wait for filer discovery before setting
the filer address function, we now set a dynamic function immediately
that returns the current filer address whenever it's called.

This eliminates the race condition where users could create users before
the goroutine completed, and provides clearer error messages when no
filer is available.

The dynamic function is HA-aware - it automatically returns whatever
filer is currently available, adapting to filer failovers.
pull/7635/head
Chris Lu 4 weeks ago
committed by GitHub
parent
commit
4cc6a2a4e5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      weed/admin/dash/admin_server.go
  2. 4
      weed/credential/filer_etc/filer_etc_store.go

28
weed/admin/dash/admin_server.go

@ -99,28 +99,22 @@ func NewAdminServer(masters string, templateFS http.FileSystem, dataDir string)
// Continue without credential manager - will fall back to legacy approach // Continue without credential manager - will fall back to legacy approach
} else { } else {
server.credentialManager = credentialManager server.credentialManager = credentialManager
glog.V(0).Infof("Credential manager initialized with store type: %s", credentialManager.GetStore().GetName())
// For stores that need filer address function, set them
// For stores that need filer address function, configure them
if store := credentialManager.GetStore(); store != nil { if store := credentialManager.GetStore(); store != nil {
if filerFuncSetter, ok := store.(interface { if filerFuncSetter, ok := store.(interface {
SetFilerAddressFunc(func() pb.ServerAddress, grpc.DialOption) SetFilerAddressFunc(func() pb.ServerAddress, grpc.DialOption)
}); ok { }); ok {
// Set up a goroutine to configure filer address function once we discover filers
go func() {
for {
filerAddr := server.GetFilerAddress()
if filerAddr != "" {
// Configure the function to dynamically return the current active filer (HA-aware)
filerFuncSetter.SetFilerAddressFunc(func() pb.ServerAddress {
return pb.ServerAddress(server.GetFilerAddress())
}, server.grpcDialOption)
glog.V(1).Infof("Set filer address function for credential manager: %s", filerAddr)
break
}
glog.V(1).Infof("Waiting for filer discovery for credential manager...")
time.Sleep(5 * time.Second)
}
}()
// Configure the filer address function to dynamically return the current active filer
// This function will be called each time credentials need to be loaded/saved,
// so it will automatically use whatever filer is currently available (HA-aware)
filerFuncSetter.SetFilerAddressFunc(func() pb.ServerAddress {
return pb.ServerAddress(server.GetFilerAddress())
}, server.grpcDialOption)
glog.V(0).Infof("Credential store configured with dynamic filer address function")
} else {
glog.V(0).Infof("Credential store %s does not support filer address function", store.GetName())
} }
} }
} }

4
weed/credential/filer_etc/filer_etc_store.go

@ -58,7 +58,7 @@ func (store *FilerEtcStore) withFilerClient(fn func(client filer_pb.SeaweedFiler
store.mu.RLock() store.mu.RLock()
if store.filerAddressFunc == nil { if store.filerAddressFunc == nil {
store.mu.RUnlock() store.mu.RUnlock()
return fmt.Errorf("filer_etc: filer address function not configured")
return fmt.Errorf("filer_etc: filer not yet available - please wait for filer discovery to complete and try again")
} }
filerAddress := store.filerAddressFunc() filerAddress := store.filerAddressFunc()
@ -66,7 +66,7 @@ func (store *FilerEtcStore) withFilerClient(fn func(client filer_pb.SeaweedFiler
store.mu.RUnlock() store.mu.RUnlock()
if filerAddress == "" { if filerAddress == "" {
return fmt.Errorf("filer_etc: filer address is empty")
return fmt.Errorf("filer_etc: no filer discovered yet - please ensure a filer is running and accessible")
} }
// Use the pb.WithGrpcFilerClient helper similar to existing code // Use the pb.WithGrpcFilerClient helper similar to existing code

Loading…
Cancel
Save