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

Set a MX timeout #25

Open
xeoncross opened this issue Feb 18, 2019 · 2 comments
Open

Set a MX timeout #25

xeoncross opened this issue Feb 18, 2019 · 2 comments

Comments

@xeoncross
Copy link

Instead of using the default resolver to lookup the MX record. I recommend using a custom resolver with a context timeout to prevent long-lived connections.

https://github.com/badoux/checkmail/blob/master/checkmail.go#L49

    const timeout = 10 * time.Millisecond
    ctx, cancel := context.WithTimeout(context.TODO(), timeout)
    defer cancel() // important to avoid a resource leak
    var r net.Resolver
    names, err := r.LookupMX(ctx, "127.0.0.1")
    if err == nil && len(names) > 0 {
        fmt.Println(names[0]) // "localhost"
    }

https://play.golang.org/p/HTW6-2o0qeT

@xeoncross
Copy link
Author

You might also want to look at caching DNS queries.

@DCtheTall
Copy link

What if the lookup function took the context as an argument so users of the library could set their own timeout duration?

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

2 participants