ca3f45c0d7c8ea372d9202eb5160c0f9268c95f2
hiram
  Wed Sep 11 10:38:12 2019 -0700
use the correct default delay fraction refs #23217

diff --git src/hg/lib/botDelay.c src/hg/lib/botDelay.c
index a8a44cb..5304629 100644
--- src/hg/lib/botDelay.c
+++ src/hg/lib/botDelay.c
@@ -2,30 +2,33 @@
  * for a little bit if IP address looks like it is
  * being just too demanding. */
 
 /* Copyright (C) 2014 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 
 #include "common.h"
 #include "net.h"
 #include "portable.h"
 #include "hgConfig.h"
 #include "cheapcgi.h"
 #include "hui.h"
 #include "hCommon.h"
 #include "botDelay.h"
 
+#define defaultDelayFrac 1.0   /* standard penalty for most CGIs */
+#define defaultWarnMs 10000    /* warning at 10 to 20 second delay */
+#define defaultExitMs 20000    /* error 429 Too Many Requests after 20+ second delay */
 
 int botDelayTime(char *host, int port, char *botCheckString)
 /* Figure out suggested delay time for ip address in
  * milliseconds. */
 {
 int sd = netMustConnect(host, port);
 char buf[256];
 netSendString(sd, botCheckString);
 netRecieveString(sd, buf);
 close(sd);
 return atoi(buf);
 }
 
 void botDelayMessage(char *ip, int millis)
 /* Print out message saying why you are stalled. */
@@ -158,54 +161,54 @@
  * in hg.conf. */
 {
 if (botException())
     return;
 
 char *host = cfgOption("bottleneck.host");
 char *port = cfgOption("bottleneck.port");
 
 if (host != NULL && port != NULL)
     botDelayCgi(host, atoi(port), noWarn, fraction);
 }
 
 void hgBotDelay()
 /* High level bot delay call - for use with regular webpage output */
 {
-hgBotDelayExt(FALSE, 1.0);
+hgBotDelayExt(FALSE, defaultDelayFrac);
 }
 
 void hgBotDelayFrac(double fraction)
 /* Like hgBotDelay, but imposes a fraction of the standard access penalty */
 {
 hgBotDelayExt(FALSE, fraction);
 }
 
 void hgBotDelayNoWarn()
 /* High level bot delay call without warning - for use with non-webpage outputs */
 {
-hgBotDelayExt(TRUE, 1.0);
+hgBotDelayExt(TRUE, defaultDelayFrac);
 }
 
 void hgBotDelayNoWarnFrac(double fraction)
 /* Like hgBotDelayNoWarn, but imposes a fraction of the standard access penalty */
 {
 hgBotDelayExt(TRUE, fraction);
 }
 
 int hgBotDelayTime()
 {
-return hgBotDelayTimeFrac(1.0);
+return hgBotDelayTimeFrac(defaultDelayFrac);
 }
 
 int hgBotDelayTimeFrac(double fraction)
 /* Get suggested delay time from cgi using the standard penalty. */
 {
 char *ip = getenv("REMOTE_ADDR");
 char *host = cfgOption("bottleneck.host");
 char *port = cfgOption("bottleneck.port");
 
 int delay = 0;
 if (host != NULL && port != NULL && ip != NULL)
     {
     char *botCheckString = getBotCheckString(ip, fraction);
     delay = botDelayTime(host, atoi(port), botCheckString);
     freeMem(botCheckString);
@@ -244,45 +247,50 @@
        "a web robot is launching queries quickly, and not even waiting for "
        "the results of one query to finish before launching another query. "
        "<b>We cannot service requests from your IP address under</b> these "
        "conditions.  (code %d) "
        "To use the genome browser functionality from a Unix command line, "
        "please read <a href='http://genome.ucsc.edu/FAQ/FAQdownloads.html#download36'>our FAQ</a> on this topic. "
        "For further help on how to access our data from a command line, "
        "or if "
        "you think this delay is being imposed unfairly, please contact genome-www@soe.ucsc.edu."
        ,hogHost, asctime(localtime(&now)), botDelayMillis);
 puts("</body></html>");
 cgiExitTime(cgiExitName, enteredMainTime);
 exit(0);
 }       /*      static void hogExit()   */
 
+
 boolean earlyBotCheck(long enteredMainTime, char *cgiName, double delayFrac, int warnMs, int exitMs)
 /* similar to botDelayCgi but for use before the CGI has started any
  * output or setup the cart of done any MySQL operations.  The boolean
  * return is used later in the CGI after it has done all its setups and
  * started output so it can issue the warning.  Pass in delayFrac 0.0
  * to use the default 1.0
  */
 {
 boolean issueWarning = FALSE;
 
 if (botException())	/* don't do this if caller is on the exception list */
     return issueWarning;
 
-if (delayFrac < 0.000001) /* passed in zero, use default 1.0 */
-    delayFrac = 1.0;
+if (delayFrac < 0.000001) /* passed in zero, use default */
+    delayFrac = defaultDelayFrac;
+if (warnMs < 1)	/* passed in zero, use default */
+    warnMs = defaultWarnMs;
+if (exitMs < 1)	/* passed in zero, use default */
+    exitMs = defaultExitMs;
 
 botDelayMillis = hgBotDelayTimeFrac(delayFrac);
 if (botDelayMillis > 0)
     {
     sleep1000(botDelayMillis);
     if (botDelayMillis > warnMs)
 	{
 	if (botDelayMillis > exitMs)
 	    hogExit(cgiName, enteredMainTime);
 	else
 	    issueWarning = TRUE;
 	}
     }
 return issueWarning;
 }	/*	boolean earlyBotCheck()	*/