Projects STRLCPY dnstt Commits 23759e20
🤬
  • Apply a timeout to upstream dials in the server.

    In my testing locally, these dials would time out after about 30 seconds
    anyway:
    	2021/04/20 23:26:46 begin session 54cafb53
    	2021/04/20 23:26:47 begin stream 54cafb53:3
    	2021/04/20 23:27:19 stream 54cafb53:3 handleStream: stream 54cafb53:3 connect upstream: dial tcp X.X.X.X:YYYY: connect: connection timed out
    	2021/04/20 23:27:19 end stream 54cafb53:3
    Which is in line with the documentation for net.Dialer:
    	https://golang.org/pkg/net/#Dialer
    	With or without a timeout, the operating system may impose its
    	own earlier timeout. For instance, TCP timeouts are often around
    	3 minutes.
    But may as well be explicit.
    
    This commit has the side effect of changing the error message from
    "connection timed out" to "i/o timeout".
    	2021/04/20 23:28:08 begin session 05b0a46e
    	2021/04/20 23:28:09 begin stream 05b0a46e:3
    	2021/04/20 23:28:39 stream 05b0a46e:3 handleStream: stream 05b0a46e:3 connect upstream: dial tcp X.X.X.X:YYYY: i/o timeout
    	2021/04/20 23:28:39 end stream 05b0a46e:3
  • Loading...
  • David Fifield committed 3 years ago
    23759e20
    1 parent 6e5ba30a
  • ■ ■ ■ ■ ■
    dnstt-server/main.go
    skipped 70 lines
    71 71   // to be the query timeout of the Quad9 DoH server.
    72 72   // https://dnsencryption.info/imc19-doe.html Section 4.2, Finding 2.4
    73 73   maxResponseDelay = 1 * time.Second
     74 + 
     75 + // How long to wait for a TCP connection to upstream to be established.
     76 + upstreamDialTimeout = 30 * time.Second
    74 77  )
    75 78   
    76 79  var (
    skipped 105 lines
    182 185  // handleStream bidirectionally connects a client stream with a TCP socket
    183 186  // addressed by upstream.
    184 187  func handleStream(stream *smux.Stream, upstream string, conv uint32) error {
    185  - upstreamConn, err := net.Dial("tcp", upstream)
     188 + dialer := net.Dialer{
     189 + Timeout: upstreamDialTimeout,
     190 + }
     191 + upstreamConn, err := dialer.Dial("tcp", upstream)
    186 192   if err != nil {
    187 193   return fmt.Errorf("stream %08x:%d connect upstream: %v", conv, stream.ID(), err)
    188 194   }
    skipped 740 lines
Please wait...
Page is in error, reload to recover