Skip to content

Commit

Permalink
fix(discovery): move close mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Oct 9, 2023
1 parent 3c0a14c commit 6aa8ac2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions pkg/discovery/p2p/discovery/disc_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ func (d *DiscV4) OnNodeRecord(ctx context.Context, handler func(ctx context.Cont
}

func (l *ListenerV4) Close() error {
l.mu.Lock()
defer l.mu.Unlock()

if l.discovery != nil {
l.discovery.Close()
}
Expand All @@ -315,8 +312,13 @@ func (l *ListenerV4) Close() error {
l.localNode = nil
}

if l.conn != nil {
return l.conn.Close()
l.mu.Lock()
conn := l.conn
l.conn = nil
l.mu.Unlock()

if conn != nil {
return conn.Close()
}

return nil
Expand Down
12 changes: 7 additions & 5 deletions pkg/discovery/p2p/discovery/disc_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ func (d *DiscV5) OnNodeRecord(ctx context.Context, handler func(ctx context.Cont
}

func (l *ListenerV5) Close() error {
l.mu.Lock()
defer l.mu.Unlock()

if l.discovery != nil {
l.discovery.Close()
}
Expand All @@ -319,8 +316,13 @@ func (l *ListenerV5) Close() error {
l.localNode = nil
}

if l.conn != nil {
return l.conn.Close()
l.mu.Lock()
conn := l.conn
l.conn = nil
l.mu.Unlock()

if conn != nil {
return conn.Close()
}

return nil
Expand Down

0 comments on commit 6aa8ac2

Please sign in to comment.