natesales / q

A tiny command line DNS client with support for UDP, TCP, DoT, DoH, DoQ and ODoH.
GNU General Public License v3.0
1.76k stars 62 forks source link

One server timeout will quit whole process when querying many servers #92

Open thanch2n opened 5 months ago

thanch2n commented 5 months ago

Aiming to test response latency against many servers then pick quickest ones, but one server timeout will exit the process, expect to complete all the quires desgard timeout ones.

Sample command:

q --verbose --trace --timeout=120s 

-s 94.140.14.14 -s 94.140.15.15 -s 94.140.14.15 -s 94.140.15.16 -s 94.140.14.140 -s 94.140.14.141 -s 223.5.5.5 -s 223.6.6.6 -s 208.67.222.222 -s 208.67.220.220 -s 208.67.222.123 -s 208.67.220.123 -s 208.67.222.2 -s 208.67.220.2 -s 185.228.168.168 -s 185.228.169.168 -s 185.228.168.10 -s 185.228.169.11 -s 185.228.168.9 -s 185.228.169.9 -s 1.1.1.1 -s 1.0.0.1 -s 1.1.1.2 -s 1.0.0.2 -s 1.1.1.3 -s 1.0.0.3 -s 8.26.56.26 -s 8.20.247.20 -s 76.76.2.0 -s 76.76.10.0 -s 76.76.2.1 -s 76.76.2.2 -s 76.76.2.3 -s 185.222.222.222 -s 45.11.45.11 -s 119.29.29.29 -s 119.28.28.28 -s 54.174.40.213 -s 52.3.100.184 -s 216.146.35.35 -s 216.146.36.36 -s 80.80.80.80 -s 80.80.81.81 -s 8.8.8.8 -s 8.8.4.4 -s 74.82.42.42 -s 180.131.144.144 -s 180.131.145.145 -s 156.154.70.1 -s 156.154.71.1 -s 156.154.70.5 -s 156.154.71.5 -s 156.154.70.2 -s 156.154.71.2 -s 156.154.70.3 -s 156.154.71.3 -s 156.154.70.4 -s 156.154.71.4 -s 193.110.81.0 -s 185.253.5.0 -s 9.9.9.9 -s 149.112.112.112 -s 9.9.9.10 -s 149.112.112.10 -s 9.9.9.11 -s 149.112.112.11 -s 195.46.39.39 -s 195.46.39.40 -s 104.155.237.225 -s 104.197.28.121 -s 101.226.4.6 -s 218.30.118.6 -s 123.125.81.6 -s 140.207.198.6 -s 64.6.64.6 -s 64.6.65.6 -s 180.184.1.1 -s 180.184.2.2 -s 149.112.121.10 -s 149.112.122.10 -s 149.112.121.20 -s 149.112.122.20 -s 149.112.121.30 -s 149.112.122.30 -s 193.17.47.1 -s 185.43.135.1 -s 94.130.180.225 -s 78.47.64.161 -s 114.114.114.114 -s 114.114.115.115 -s 114.114.114.119 -s 114.114.115.119 -s 114.114.114.110 -s 114.114.115.110 -s 35.215.30.118 -s 35.215.48.207 -s 88.198.92.222 -s 117.50.10.10 -s 52.80.52.52 -s 117.50.11.11 -s 52.80.66.66 -s 217.160.70.42 -s 101.101.101.101 -s 101.102.103.104 -s 193.58.251.251 -s 130.59.31.248 -s 77.88.8.8 -s 77.88.8.1 -s 77.88.8.88 -s 77.88.8.2 -s 77.88.8.3 -s 77.88.8.7 -s 5.2.75.75 -s 45.67.219.208 -s 176.9.93.198 -s 176.9.1.117 -s 51.38.83.141 -s 51.38.82.198 -s 174.138.21.128 -s 172.104.93.80 -s 45.76.113.31 

 -t A google.com --stats

Tried to add a for before select in main.go like below, but it will panic when one server timeout:

FOR:
    for {
        select {
        case <-time.After(opts.Timeout):
            fmt.Printf("timeout after %s\n", opts.Timeout)
            // return fmt.Errorf("timeout after %s", opts.Timeout)
        case err := <-errChan:
            // end marker
            if err == nil {
                break FOR
            } else {
                fmt.Printf("got err from errChan: %s\n", err)
            }
        }
    }
DAP server listening at: 127.0.0.1:54945
Type 'dlv help' for list of commands.
time="2024-06-21T10:30:44+08:00" level=debug msg="Name: 94.140.14.14"
time="2024-06-21T10:30:44+08:00" level=debug msg="RR types: [A]"
time="2024-06-21T10:30:44+08:00" level=debug msg="Server(s): [94.140.14.14 94.140.15.15 94.140.14.15 94.140.15.16 94.140.14.140 94.140.14.141 223.5.5.5 223.6.6.6 208.67.222.222 208.67.220.220 208.67.222.123 208.67.220.123 208.67.222.2 208.67.220.2 185.228.168.168 185.228.169.168 185.228.168.10 185.228.169.11 185.228.168.9 185.228.169.9 1.1.1.1 1.0.0.1 1.1.1.2 1.0.0.2 1.1.1.3 1.0.0.3 8.26.56.26 8.20.247.20 76.76.2.0 76.76.10.0 76.76.2.1 76.76.2.2 76.76.2.3 185.222.222.222 45.11.45.11 119.29.29.29 119.28.28.28 54.174.40.213 52.3.100.184 216.146.35.35 216.146.36.36 80.80.80.80 80.80.81.81 8.8.8.8 8.8.4.4 74.82.42.42 180.131.144.144 180.131.145.145 156.154.70.1 156.154.71.1 156.154.70.5 156.154.71.5 156.154.70.2 156.154.71.2 156.154.70.3 156.154.71.3 156.154.70.4 156.154.71.4 193.110.81.0 185.253.5.0 9.9.9.9 149.112.112.112 9.9.9.10 149.112.112.10 9.9.9.11 149.112.112.11 195.46.39.39 195.46.39.40 104.155.237.225 104.197.28.121 101.226.4.6 218.30.118.6 123.125.81.6 140.207.198.6 64.6.64.6 64.6.65.6 180.184.1.1 180.184.2.2 149.112.121.10 149.112.122.10 149.112.121.20 149.112.122.20 149.112.121.30 149.112.122.30 193.17.47.1 185.43.135.1 94.130.180.225 78.47.64.161 114.114.114.114 114.114.115.115 114.114.114.119 114.114.115.119 114.114.114.110 114.114.115.110 35.215.30.118 35.215.48.207 88.198.92.222 117.50.10.10 52.80.52.52 117.50.11.11 52.80.66.66 217.160.70.42 101.101.101.101 101.102.103.104 193.58.251.251 130.59.31.248 77.88.8.8 77.88.8.1 77.88.8.88 77.88.8.2 77.88.8.3 77.88.8.7 5.2.75.75 45.67.219.208 176.9.93.198 176.9.1.117 51.38.83.141 51.38.82.198 174.138.21.128 172.104.93.80 45.76.113.31]"
time="2024-06-21T10:30:44+08:00" level=debug msg="Using server 94.140.14.14:53 with transport plain"
time="2024-06-21T10:30:44+08:00" level=debug msg="Using UDP with TCP fallback: 94.140.14.14:53"
timeout after 2s
got err from errChan: exchange: read udp 198.18.0.1:63045->94.140.14.14:53: i/o timeout
got err from errChan: no reply from server
timeout after 2s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa55827b]

goroutine 4 [running]:
main.driver.func2()
    /Users/c/Documents/Pjt/p1/golang/dns_q/main.go:449 +0x111b
created by main.driver in goroutine 1
    /Users/c/Documents/Pjt/p1/golang/dns_q/main.go:409 +0x25f0
Process 53301 has exited with status 2
Detaching