Skip to content

Commit

Permalink
Merge pull request #10 from claranet/9-fix-concurrent-map-read-and-ma…
Browse files Browse the repository at this point in the history
…p-write

9 fix concurrent map read and map write
  • Loading branch information
dvdme authored Dec 24, 2024
2 parents f542877 + 7b14205 commit 5efdfad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BINARY_SUFFIX=
BINARY=go-dnsmasq${BINARY_SUFFIX}
VERSION=1.3.0
VERSION=1.3.1
B_LDFLAGS=-X main.Version=${VERSION}
R_LDFLAGS=-w -s -X main.Version=${VERSION}
TEST=$$(go list ./... | grep -v 'vendor')
Expand All @@ -25,19 +25,23 @@ lint-ci:
if ! command -v golangci-lint; then go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANG_CI_LINT_VERSION}; fi
golangci-lint run -v

run:
# debug run the app
go run -race main.go --listen 127.0.0.1:5300 --nameservers 8.8.8.8,1.1.1.1 --verbose --rstale-ttl 30 --rcache 10 --rcache-non-negative --rcache-ttl 10 --rcache-ttl-from-resp --rcache-ttl-max 3600

build:
go build --ldflags "${B_LDFLAGS}" -o ${BINARY}

release:
# Darwin
GOOS=darwin GOARCH=amd64 go build --ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_darwin_amd64
GOOS=darwin GOARCH=arm64 go build --ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_darwin_arm64
GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_darwin_amd64
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_darwin_arm64
# Linux
GOOS=linux GOARCH=amd64 go build --ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_linux_amd64
GOOS=linux GOARCH=arm64 go build --ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_linux_arm64
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_linux_amd64
GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "${R_LDFLAGS}" -o ./binaries/${BINARY}_linux_arm64

test:
go test ./... -list=. -timeout=30s -parallel=1
go test -race ./... -list=. -timeout=30s -parallel=1

clean:
go clean
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
2 changes: 2 additions & 0 deletions cache/hit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ func (c *Cache) Hit(question dns.Question, dnssec, tcp bool, msgid uint16, keepS
m1.Compress = true
// Even if something ended up with the TC bit *in* the cache, set it to off
m1.Truncated = false
c.Lock()
if valid {
c.m[key].hits++
} else {
c.m[key].staleHits++
}
c.Unlock()
// Remove if stale expired
if time.Since(staleExp) > 0 {
c.Remove(key)
Expand Down

0 comments on commit 5efdfad

Please sign in to comment.