Skip to content

Commit 9e03c61

Browse files
authored
Merge pull request #50 from mrozitron/mrozitron-drop-dial-error-checks
simulator: don't treat dial errors as errors
2 parents 66c7320 + 270f8fe commit 9e03c61

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

simulator/simulator.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ func (s *TCPConnectSimulator) Simulate(ctx context.Context, dst string) error {
7272
if conn != nil {
7373
conn.Close()
7474
}
75-
// This will likely generate some superfluous io-timeout error messages, but if the
76-
// user specifies a misconfigured interface, they'll see the simulation failing.
77-
if err != nil && (!isSoftError(err, "connect: connection refused") || isDialError(err)) {
75+
// Ignore "connection refused" and timeouts.
76+
if err != nil && !isSoftError(err, "connect: connection refused") {
7877
return err
7978
}
8079
return nil
@@ -111,24 +110,14 @@ func (s *DNSResolveSimulator) Simulate(ctx context.Context, dst string) error {
111110
host = utils.FQDN(host)
112111

113112
_, err := r.LookupHost(ctx, host)
114-
// Ignore "no such host". Will ignore timeouts as well, so check for dial errors.
115-
if err != nil && (!isSoftError(err, "no such host") || isDialError(err)) {
113+
// Ignore "no such host" and timeouts.
114+
if err != nil && !isSoftError(err, "no such host") {
116115
return err
117116
}
118117

119118
return nil
120119
}
121120

122-
// isDialError scans an error message for signs of a dial error, returning a boolean.
123-
func isDialError(err error) bool {
124-
// Errors we're after are of the form:
125-
// lookup abc.sandbox.alphasoc.xyz. on A.B.C.D:53: dial udp E.F.G.H:0->A.B.C.D:53: i/o timeout
126-
// TODO: something more robust? I don't want to double-dial though.
127-
return isTimeout(err) &&
128-
strings.Contains(err.Error(), "dial") &&
129-
strings.Count(err.Error(), "->") == 1
130-
}
131-
132121
func isTimeout(err error) bool {
133122
netErr, ok := err.(net.Error)
134123
if !ok {

simulator/spambot.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ func (s *Spambot) Hosts(scope string, size int) ([]string, error) {
8989
for n := 0; len(hosts) < size && n < len(idx); n++ {
9090
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
9191
host := utils.FQDN(domains[idx[n]])
92-
mx, err := rv.LookupMX(ctx, host)
92+
mx, _ := rv.LookupMX(ctx, host)
9393
cancel()
9494
// Check error message for sign of resolver/routing issue.
95-
if err != nil && isDialError(err) {
96-
return hosts, err
97-
}
95+
// TODO: at some point we'll want to check dialer errors for a sign of resolver
96+
// problems
9897
if len(mx) > 0 {
9998
host := strings.TrimSuffix(mx[0].Host, ".")
10099
if !seen[host] {

simulator/tunnel-dns.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (s *Tunnel) Simulate(ctx context.Context, host string) error {
5656
defer cancelFn()
5757
_, err := r.LookupTXT(ctx, fmt.Sprintf("%s.%s", label, host))
5858

59-
// Ignore "no such host". Will ignore timeouts as well, so check for dial errors.
60-
if err != nil && (!isSoftError(err, "no such host") || isDialError(err)) {
59+
// Ignore "no such host". Will ignore timeouts as well.
60+
if err != nil && !isSoftError(err, "no such host") {
6161
return err
6262
}
6363

0 commit comments

Comments
 (0)