Skip to content

Commit

Permalink
another try to remove job observer leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Oct 8, 2024
1 parent 1e5eeda commit c1b586d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions services/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ func (s *Observer) Close() {
s.mux.Lock()
defer s.mux.Unlock()
if !s.closed {
close(s.C)
s.closed = true
close(s.C)
}
}

func (s *Observer) isClosed() bool {
func (s *Observer) Push(v LogItem) {
s.mux.Lock()
defer s.mux.Unlock()
return s.closed
}

func (s *Observer) Push(v LogItem) {
if !s.isClosed() {
s.C <- v
if s.closed {
return
}
s.C <- v
if v.Level == Close {
close(s.C)
s.closed = true
}
}

Expand Down Expand Up @@ -178,9 +179,6 @@ func (s *Job) log(l LogItem) error {
s.l = append(s.l, l)
for _, o := range s.observers {
o.Push(l)
if l.Level == Close {
o.Close()
}
}
if s.main {
err := s.storage.Pub(s.Context, s.ID, &l)
Expand Down

0 comments on commit c1b586d

Please sign in to comment.