Skip to content

Commit

Permalink
Create ticker outside critical section
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVerkada committed Feb 7, 2024
1 parent 5662268 commit dfc49cb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,8 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade
query := &query{nameWithSuffix, queryChan}
c.mu.Lock()
c.queries = append(c.queries, query)
ticker := time.NewTicker(c.queryInterval)
c.mu.Unlock()

defer ticker.Stop()
defer func() {
c.mu.Lock()
defer c.mu.Unlock()
Expand All @@ -180,6 +178,9 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade
}
}()

ticker := time.NewTicker(c.queryInterval)
defer ticker.Stop()

c.sendQuestion(nameWithSuffix)
for {
select {
Expand Down

0 comments on commit dfc49cb

Please sign in to comment.