Skip to content

Commit

Permalink
simulator: drop isDialError() alltogether
Browse files Browse the repository at this point in the history
Will come up with a workable approach.
  • Loading branch information
kmroz committed Oct 27, 2021
1 parent a382821 commit 270f8fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
3 changes: 1 addition & 2 deletions simulator/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (s *StratumMiner) Simulate(ctx context.Context, dst string) error {
conn.Close()
}

// TODO Dropping isDialError() as an error as it's causing too many io-timeout messages.
if isSoftError(err, "connect: connection refused") || isDialError(err) {
if isSoftError(err, "connect: connection refused") {
return nil
}
return err
Expand Down
19 changes: 4 additions & 15 deletions simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (s *TCPConnectSimulator) Simulate(ctx context.Context, dst string) error {
if conn != nil {
conn.Close()
}
// TODO: Dropping isDialError() check, as it's causing too many io-timeout messages.
if err != nil && !isSoftError(err, "connect: connection refused") && !isDialError(err) {
// Ignore "connection refused" and timeouts.
if err != nil && !isSoftError(err, "connect: connection refused") {
return err
}
return nil
Expand Down Expand Up @@ -110,25 +110,14 @@ func (s *DNSResolveSimulator) Simulate(ctx context.Context, dst string) error {
host = utils.FQDN(host)

_, err := r.LookupHost(ctx, host)
// Ignore "no such host". Will ignore timeouts as well, so check for dial errors.
// TODO: Dropping isDialError() check, as it's causing too many io-timeout messages.
if err != nil && !isSoftError(err, "no such host") && !isDialError(err) {
// Ignore "no such host" and timeouts.
if err != nil && !isSoftError(err, "no such host") {
return err
}

return nil
}

// isDialError scans an error message for signs of a dial error, returning a boolean.
func isDialError(err error) bool {
// Errors we're after are of the form:
// 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
// TODO: something more robust? I don't want to double-dial though.
return isTimeout(err) &&
strings.Contains(err.Error(), "dial") &&
strings.Count(err.Error(), "->") == 1
}

func isTimeout(err error) bool {
netErr, ok := err.(net.Error)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions simulator/tunnel-dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (s *Tunnel) Simulate(ctx context.Context, host string) error {
defer cancelFn()
_, err := r.LookupTXT(ctx, fmt.Sprintf("%s.%s", label, host))

// Ignore "no such host". Will ignore timeouts as well, so check for dial errors.
if err != nil && !isSoftError(err, "no such host") && !isDialError(err) {
// Ignore "no such host". Will ignore timeouts as well.
if err != nil && !isSoftError(err, "no such host") {
return err
}

Expand Down

0 comments on commit 270f8fe

Please sign in to comment.