Skip to content

Set a MX timeout #25

Description

@xeoncross

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions