Skip to content

Commit

Permalink
fix: add err return to srv's Close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Selivanov committed Jun 26, 2023
1 parent 2012202 commit 67104a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type IService interface {

Tags() map[string]struct{}

Close()
Close() error
}

// TODO split address field to host and port
Expand Down Expand Up @@ -85,7 +85,9 @@ func (n *BaseService) Tags() map[string]struct{} {
return n.tags
}

func (n *BaseService) Close() {}
func (n *BaseService) Close() error {
return nil
}

// generateServiceID create BaseService unique id by
// hashing given address string
Expand Down
10 changes: 8 additions & 2 deletions services_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ func (l *ServicesList) RemoveFromHealthyByIndex(i int) {
l.mu.Lock()
defer l.mu.Unlock()

l.healthy[i].Close()
if err := l.healthy[i].Close(); err != nil {
logger.Log().Warn(fmt.Errorf("unexpected error during service Close(): %w", err).Error())
}

l.healthy = append(l.healthy[:i], l.healthy[i+1:]...)
}

Expand All @@ -330,7 +333,10 @@ func (l *ServicesList) RemoveFromJail(srv service.IService) {
defer l.mu.Unlock()
l.mu.Lock()

srv.Close()
if err := srv.Close(); err != nil {
logger.Log().Warn(fmt.Errorf("unexpected error during service Close(): %w", err).Error())
}

delete(l.jail, srv.ID())
}

Expand Down

0 comments on commit 67104a3

Please sign in to comment.