Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handle #2

Open
abolinhas opened this issue Mar 19, 2022 · 1 comment
Open

Error handle #2

abolinhas opened this issue Mar 19, 2022 · 1 comment

Comments

@abolinhas
Copy link

abolinhas commented Mar 19, 2022

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/[email protected]/resolverdns.go:46 +0x6d
github.com/d3mondev/resolvermt.(*clientDNS).startThreads.func1(0xc014deea40?)
        C:/Users/andre/go/pkg/mod/github.com/d3mondev/[email protected]/client_dns.go:50 +0x3f
created by github.com/d3mondev/resolvermt.(*clientDNS).startThreads
        C:/Users/andre/go/pkg/mod/github.com/d3mondev/[email protected]/client_dns.go:42 +0x59
root@proxy01:/usr/share/artica-postfix/bin/go-shield/server/bin# ./go-shield-server
@abolinhas
Copy link
Author

any update or the project is dead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant