Fix Debian bug #232276

Hrvoje Niksic <[email protected]> Thu, 05 May 2005 11:46:32 +0200
Newsgroups gmane.comp.web.wget.patches
Message-ID <[email protected]>
This patch fixed Debian bug #232276, available at
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=232276

The problem was that the "sleep_adjust" value (normally used for
correcting sleep times against the clock) wasn't reset for the next
download and the old, ridiculously large value got used.  The value
got ridiculously large because Wget was suspended for a long time,
which means that the sleep took way longer than Wget was hoping it
would.

Other than the obvious fix of resetting sleep_adjust in
limit_bandwidth_reset, this patch also makes sure that weirdly large
values of sleep_adjust are limited to "reasonable" +-500 ms.

It would be kind of nice if Debian forwarded bug reports such as this
one to us.

2005-05-05  Hrvoje Niksic  <[email protected]>

	* retr.c (limit_bandwidth_reset): Reset sleep_adjust.
	(limit_bandwidth): Don't allow huge "adjustment" values that
	result from being suspended for a while.

Index: src/retr.c
===================================================================
RCS file: /pack/anoncvs/wget/src/retr.c,v
retrieving revision 1.96
diff -u -r1.96 retr.c
--- src/retr.c	2005/05/03 15:24:30	1.96
+++ src/retr.c	2005/05/05 09:43:10
@@ -82,6 +82,7 @@
 {
   limit_data.chunk_bytes = 0;
   limit_data.chunk_start = 0;
+  limit_data.sleep_adjust = 0;
 }
 
 /* Limit the bandwidth by pausing the download for an amount of time.
@@ -125,6 +126,12 @@
 	 desired and the actual sleep, and adjust the next sleep by
 	 that amount.  */
       limit_data.sleep_adjust = slp - (t1 - t0);
+      /* If sleep_adjust is very large, it's likely due to suspension
+	 and not clock inaccuracy.  Don't enforce those.  */
+      if (limit_data.sleep_adjust > 500)
+	limit_data.sleep_adjust = 500;
+      else if (limit_data.sleep_adjust < -500)
+	limit_data.sleep_adjust = -500;
     }
 
   limit_data.chunk_bytes = 0;