246448930e2c91af800f5a65e090182588517d2b max Tue May 9 04:53:24 2023 -0700 adding note about not-applied botDelay to measureTiming, and moving a few lines in botDelay where they belong, refs #14567 diff --git src/hg/lib/botDelay.c src/hg/lib/botDelay.c index 1183339..e10bdef 100644 --- src/hg/lib/botDelay.c +++ src/hg/lib/botDelay.c @@ -7,30 +7,32 @@ #include "common.h" #include "net.h" #include "portable.h" #include "hgConfig.h" #include "cheapcgi.h" #include "hui.h" #include "hCommon.h" #include "botDelay.h" #include "jsonWrite.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 botDelayWarnMs = 0; /* global so the previously used value can be retrieved */ + 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); } char *botDelayWarningMsg(char *ip, int millis) /* return the string for the default botDelay message * not all users of botDelay want the message to go to stderr @@ -252,39 +254,51 @@ * 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, pass in 0 for warnMs and exitMs to use defaults, * and exitType is either 'html' or 'json' to do that type of exit output in * the case of hogExit(); */ { 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 */ delayFrac = defaultDelayFrac; -if (warnMs < 1) /* passed in zero, use default */ - warnMs = defaultWarnMs; + +botDelayWarnMs = warnMs; +if (botDelayWarnMs < 1) /* passed in zero, use default */ + botDelayWarnMs = defaultWarnMs; + if (exitMs < 1) /* passed in zero, use default */ exitMs = defaultExitMs; botDelayMillis = hgBotDelayTimeFrac(delayFrac); if (botDelayMillis > 0) { - int msAboveWarning = botDelayMillis - warnMs; + if (botDelayMillis > botDelayWarnMs) + { + if (botDelayMillis > exitMs) /* returning immediately */ + { + int msAboveWarning = botDelayMillis - botDelayWarnMs; int retryAfterSeconds = 0; if (msAboveWarning > 0) retryAfterSeconds = 1 + (msAboveWarning / 10); - if (botDelayMillis > warnMs) - { - if (botDelayMillis > exitMs) /* returning immediately */ hogExit(cgiName, enteredMainTime, exitType, retryAfterSeconds); + } else issueWarning = TRUE; - sleep1000(botDelayMillis); /* sleep when > warnMs and < exitMs */ + sleep1000(botDelayMillis); /* sleep when > botDelayWarnMs and < exitMs */ } } return issueWarning; /* caller can decide on their type of warning */ } /* boolean earlyBotCheck() */ + +int hgBotWarnMs() +/* get number of millis that are tolerated until a warning is shown on the most recent call to earlyBotCheck */ +{ + return botDelayWarnMs; +} +