Skip to content

Commit

Permalink
[AUTOPR] dnscache improvements (Vonage#224)
Browse files Browse the repository at this point in the history
* close wait channel on ctx cancellation

* set a default error on wait entries

---------

Co-authored-by: nicolaasuni-vonage <[email protected]>
  • Loading branch information
github-actions[bot] and nicolaasuni-vonage authored Mar 7, 2024
1 parent 8ca14ca commit 65e852f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.83.1
1.83.2
2 changes: 1 addition & 1 deletion examples/service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
replace github.com/Vonage/gosrvlib => ../..

require (
github.com/Vonage/gosrvlib v1.83.1
github.com/Vonage/gosrvlib v1.83.2
github.com/golang/mock v1.6.0
github.com/jstemmer/go-junit-report v1.0.0
github.com/prometheus/client_golang v1.19.0
Expand Down
4 changes: 3 additions & 1 deletion pkg/dnscache/dnscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dnscache

import (
"context"
"errors"
"fmt"
"net"
"sync"
Expand Down Expand Up @@ -113,6 +114,7 @@ func (c *Cache) LookupHost(ctx context.Context, host string) ([]string, error) {
select {
case <-item.wait:
case <-ctx.Done():
close(item.wait)
return nil, fmt.Errorf("context canceled: %w", ctx.Err())
}

Expand All @@ -133,7 +135,7 @@ func (c *Cache) LookupHost(ctx context.Context, host string) ([]string, error) {
wait := make(chan struct{})
defer close(wait)

c.set(host, nil, nil, wait)
c.set(host, nil, errors.New("held"), wait)
c.mux.Unlock()

addrs, err := c.resolver.LookupHost(ctx, host)
Expand Down

0 comments on commit 65e852f

Please sign in to comment.