Skip to content

Commit

Permalink
Correct cache behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Fangliding authored Sep 15, 2024
1 parent d2e79c2 commit 83cffab
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions transport/internet/tls/ech.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ var (
)

func QueryRecord(domain string, server string) (string, error) {
mutex.RLock()
defer mutex.RUnlock()
rec, found := dnsCache[domain]
if found && rec.expire.After(time.Now()) {
return "", nil
return rec.record, nil
}
mutex.Lock()
defer mutex.Unlock()
record, err := dohQuery(server, domain)
if err != nil {
return "", err
}
rec.record = record
rec.expire = time.Now().Add(time.Second * 600)
dnsCache[domain] = rec
return record, nil
}

Expand Down

0 comments on commit 83cffab

Please sign in to comment.