changed embedded mutex to private field (#217)
Some checks failed
sync / sync (push) Failing after 16m12s
test / test (push) Failing after 17m28s
coverage / build (push) Failing after 17m40s

This commit is contained in:
2025-05-25 03:15:03 +05:00
committed by GitHub
parent 0f8f12aee0
commit 13f90ff716
13 changed files with 151 additions and 151 deletions

View File

@@ -96,9 +96,9 @@ func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOptio
}
type service struct {
done chan struct{}
opts Options
sync.RWMutex
done chan struct{}
opts Options
mu sync.RWMutex
stopped bool
}
@@ -321,9 +321,9 @@ func (s *service) Health() bool {
func (s *service) Start() error {
var err error
s.RLock()
s.mu.RLock()
config := s.opts
s.RUnlock()
s.mu.RUnlock()
for _, cfg := range s.opts.Configs {
if cfg.Options().Struct == nil {
@@ -380,9 +380,9 @@ func (s *service) Start() error {
}
func (s *service) Stop() error {
s.RLock()
s.mu.RLock()
config := s.opts
s.RUnlock()
s.mu.RUnlock()
if config.Loggers[0].V(logger.InfoLevel) {
config.Loggers[0].Info(s.opts.Context, fmt.Sprintf("stoppping [service] %s", s.Name()))
@@ -457,13 +457,13 @@ func (s *service) Run() error {
// notifyShutdown marks the service as stopped and closes the done channel.
// It ensures the channel is closed only once, preventing multiple closures.
func (s *service) notifyShutdown() {
s.Lock()
s.mu.Lock()
if s.stopped {
s.Unlock()
s.mu.Unlock()
return
}
s.stopped = true
s.Unlock()
s.mu.Unlock()
close(s.done)
}