title: wget using --timeout and --tries together
body: <p>How long would you expect this command to take before exiting?</p>
  
  <p><code>wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"</code></p>
  
  <p>I would expect a timeout of 1 seconds and 2 tries would mean 2 seconds, but it takes 6.025 seconds</p>
  
  <pre><code>wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"
  --2017-04-27 16:49:12--http://www.google.com:81/not-there
  Resolving www.google.com (www.google.com)... 209.85.203.105, 209.85.203.103, 209.85.203.99, ...
  Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|2a00:1450:4009:80d::2004|:81... failed: Network is unreachable.
  </code></pre>
  
  <p>I don't know why it tries 6 times before quitting.</p>
  
  <p>It seems like <code>tries</code> is for retrying. If I set <code>--retry-connrefused</code> it at least does the retry, but still the total time taken isn't what I would expect. I'd like to be able to decide how many times it should try on a timeout.</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>After a suggestion from @Socowi I tried using waitretry in combination with retry-connrefused and got the same behaviour:</p>
  
  <pre><code>$ wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
  --2017-04-27 20:29:47--  http://www.google.com:81/not-there
  Resolving www.google.com (www.google.com)... 2a00:1450:400b:c00::68, 209.85.203.99, 209.85.203.147, ...
  Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
  Retrying.
  
  --2017-04-27 20:29:54--  (try: 2)  http://www.google.com:81/not-there
  Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
  Giving up.
  </code></pre>
  
  <p><strong>Edit Two</strong></p>
  
  <p>I was really confused when two identical commands behaved differently.</p>
  
  <pre><code>root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
  converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -&gt; 'http://www.google.com:81/not-there' (UTF-8)
  --2017-04-27 19:50:28--  http://www.google.com:81/not-there
  Resolving www.google.com (www.google.com)... 216.58.211.164, 2a00:1450:4009:805::2004
  Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address.
  Retrying.
  
  --2017-04-27 19:50:29--  (try: 2)  http://www.google.com:81/not-there
  Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address.
  Giving up.
  
  root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
  converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -&gt; 'http://www.google.com:81/not-there' (UTF-8)
  --2017-04-27 19:50:35--  http://www.google.com:81/not-there
  Resolving www.google.com (www.google.com)... 209.85.203.104, 209.85.203.147, 209.85.203.106, ...
  Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address.
  Retrying.
  
  --2017-04-27 19:50:41--  (try: 2)  http://www.google.com:81/not-there
  Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
  Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address.
  Giving up.
  </code></pre>
  
  <p>I thought I was going a bit crazy, but it was only when @Socowi pointed out in the comments that the IPs each retry were different that it clicked. It depends on the number of possible IPs being returned. The magic number 7 (retries) I was seeing was number the IP options. When I just choose one specific IP it only tries it once.</p>