Error handle
abolinhas opened this issue · comments
Hi
How can i catch any error of dns resolve withou crashing the APP?
I mean, this is my code:
resolvers := []string{
dns1,
dns2,
}
url := strings.TrimSuffix(w, "\n")
domains := []string{
url + ".filter.site.com",
}
client := resolvermt.New(resolvers, 3, 1000, 5)
defer client.Close()
results := client.Resolve(domains, resolvermt.TypeTXT)
for _, record := range results {
s := strings.Split(record.Answer, ":")
cat_name := strings.Replace(s[01], " ", "_", -1)
cat_name = strings.Replace(cat_name, "/", "_", -1)
_catID, _ = strconv.Atoi(s[0])
_catName = cat_name
internal.InMemoryCache.Append(w, []byte(strconv.Itoa(_catID)+":"+_catName))
elapsed := time.Since(start).Microseconds()
if isDebug {
log.Printf("%s founded in DNS Cloud Servers with category %s (%d) - took %d μs", w, _catName, _catID, elapsed)
}
}
When I try resolve a valid address it's works perfectly:
root@proxy01:~# curl http://localhost:3333/get-categories?website=sapo.pt
{"category_id":"3","category_name":"Society"}
But if I try an invalid url, the app craches:
root@proxy01:~# curl http://localhost:3333/get-categories?website=sapo.pt^^^
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x6b792d]
goroutine 1999 [running]:
github.com/d3mondev/resolvermt.(*resolverDNS).Resolve(0xc01754ea80, {0xc016fff8c0, 0x1d}, 0x0?)
C:/Users/andre/go/pkg/mod/github.com/d3mondev/resolvermt@v0.3.2/resolverdns.go:46 +0x6d
github.com/d3mondev/resolvermt.(*clientDNS).startThreads.func1(0xc014deea40?)
C:/Users/andre/go/pkg/mod/github.com/d3mondev/resolvermt@v0.3.2/client_dns.go:50 +0x3f
created by github.com/d3mondev/resolvermt.(*clientDNS).startThreads
C:/Users/andre/go/pkg/mod/github.com/d3mondev/resolvermt@v0.3.2/client_dns.go:42 +0x59
root@proxy01:/usr/share/artica-postfix/bin/go-shield/server/bin# ./go-shield-server
any update or the project is dead?