Download raw body.
gotd.conf: adds time suffixes to timeouts
On Tue, Jan 03, 2023 at 10:48:01AM +0100, Omar Polo wrote:
> I had something like this lying around in a private parse.y, would it
> be useful for gotd too? It just allows for a slightly more nice
> timeout definition, which is quite niche.
I like this. ok
> diff 40b85cca5d86ebef3a353efd464af989c3ebf18b 0428eb4f1414af686a05fa3569b6639a47880b53
> commit - 40b85cca5d86ebef3a353efd464af989c3ebf18b
> commit + 0428eb4f1414af686a05fa3569b6639a47880b53
> blob - ba00f127e7a704c7c95a42f2210fd109af6de5a3
> blob + a45eb65170386548a9b8a2b7812f7309eebdc6f6
> --- gotd/gotd.conf.5
> +++ gotd/gotd.conf.5
> @@ -55,7 +55,19 @@ The default timeout is 3600 seconds (1 hour).
> If this timeout is exceeded while a Git protocol request is being processed,
> the request will be aborted and the connection will be terminated.
> .Pp
> -The default timeout is 3600 seconds (1 hour).
> +The timeout value may also have a suffix indicating its unit of measure.
> +Supported suffixes are:
> +.Pp
> +.Bl -tag -compact -width tenletters
> +.It Ar s No or Ar S
> +seconds
> +.It Ar m No or Ar M
> +minutes
> +.It Ar h No or Ar H
> +hours
> +.El
> +.Pp
> +The default timeout is 1h (3600 seconds, one hour).
> This should only be changed if legitimate requests are exceeding the default
> timeout for some reason, such as the server spending an extraordinary
> amount of time generating a pack file.
> @@ -205,7 +217,7 @@ connection request timeout 7200 # 2 hours
> }
>
> # Use a larger request timeout value:
> -connection request timeout 7200 # 2 hours
> +connection request timeout 2h
>
> # Some users are granted a higher concurrent connection limit:
> connection {
> blob - 580f43381ccf163eac2c738800e7efd25c7562e4
> blob + a19acba378f3c3be18670a3ec12ad2b20ee61fdf
> --- gotd/parse.y
> +++ gotd/parse.y
> @@ -147,6 +147,57 @@ timeout : NUMBER {
> $$.tv_sec = $1;
> $$.tv_usec = 0;
> }
> + | STRING {
> + const char *errstr;
> + const char *type = "seconds";
> + size_t len;
> + int mul = 1;
> +
> + if (*$1 == '\0') {
> + yyerror("invalid number of seconds: %s", $1);
> + free($1);
> + YYERROR;
> + }
> +
> + len = strlen($1);
> + switch ($1[len - 1]) {
> + case 'S':
> + case 's':
> + $1[len - 1] = '\0';
> + break;
> + case 'M':
> + case 'm':
> + type = "minutes";
> + mul = 60;
> + $1[len - 1] = '\0';
> + break;
> + case 'H':
> + case 'h':
> + type = "hours";
> + mul = 60 * 60;
> + $1[len - 1] = '\0';
> + break;
> + }
> +
> + $$.tv_usec = 0;
> + $$.tv_sec = strtonum($1, 0, INT_MAX, &errstr);
> + if (errstr) {
> + yyerror("number of %s is %s: %s", type,
> + errstr, $1);
> + free($1);
> + YYERROR;
> + }
> +
> + if ($$.tv_sec > INT_MAX / mul) {
> + yyerror("number of %s is too too large: %s",
> + type, $1);
> + free($1);
> + YYERROR;
> + }
> +
> + $$.tv_sec *= mul;
> + free($1);
> + }
> ;
>
> main : UNIX_SOCKET STRING {
>
>
gotd.conf: adds time suffixes to timeouts